Skip to main content

A tool for rapidly creating containerised development environments

Project description

Container Magic - Sparkles the Otter

container-magic

Define your container workflow in a single YAML file. Container-magic generates a Dockerfile, build script, and run script that work with Docker or Podman - container-magic is not a dependency of your final product.

PyPI version Python versions CI Status License: MIT

How It Works

You write a cm.yaml. Container-magic generates a Dockerfile, build.sh, and run.sh from it. These generated files are committed to your repository so that anyone can build and run the project with Docker or Podman.

For development, cm build and cm run read the config directly and handle workspace mounting, user identity mapping, and runtime features automatically.

Quick Start

pip install container-magic
cm init python:3.11 my-project
cd my-project
cm build
cm run python --version

On Nix, run it without installing - or add it as a flake input:

nix run github:markhedleyjones/container-magic -- init python:3.11 my-project
nix profile install github:markhedleyjones/container-magic   # install cm

The flake exposes packages.default / apps.default (the cm CLI) and an overlays.default for declarative setups.

A minimal cm.yaml:

names:
  image: my-project
  workspace: workspace
  user: nonroot

stages:
  base:
    from: python:3.11-slim
    steps:
      - apt-get:
          install:
            - git
            - build-essential
      - pip:
          install:
            - numpy
            - pandas

  development:
    from: base

  production:
    from: base

Build and run the production image:

./build.sh
./run.sh python workspace/train.py

Key Features

  • Development and production from one config - live-mounted workspace in dev, baked-in code in prod
  • Automatic user handling - host user identity in dev, dedicated user in prod, no manual setup
  • GPU, display, and audio - NVIDIA GPU passthrough, X11/Wayland forwarding, PulseAudio/PipeWire
  • Custom commands - define once, use in both dev and prod with port publishing and environment variables
  • Multi-stage builds - share steps between stages, pip packages install into the base image's Python (no venv duplication)
  • Transparent execution - run commands from anywhere in your repo with automatic path translation
  • Data volumes - shorthand for sibling folders (outputs, cache) that persist across runs without entering the image
  • AWS credential forwarding - mount host AWS config into the container
  • Cached assets - download models and datasets once, reuse across builds

Documentation

Full documentation is available at markhedleyjones.com/container-magic.

Page Contents
Getting Started Installation, first project, workflow
Configuration Full YAML reference - names, runtime, stages, commands
Build Steps Package managers, custom commands, layer caching
Cached Assets Asset downloading, caching, and cache management
User Handling Dev vs prod users, copy ownership, permissions
Troubleshooting Common issues and solutions

Contributing

Contributions and feedback welcome! Open an issue or pull request on GitHub.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

container_magic-5.6.0.tar.gz (49.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

container_magic-5.6.0-py3-none-any.whl (57.6 kB view details)

Uploaded Python 3

File details

Details for the file container_magic-5.6.0.tar.gz.

File metadata

  • Download URL: container_magic-5.6.0.tar.gz
  • Upload date:
  • Size: 49.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for container_magic-5.6.0.tar.gz
Algorithm Hash digest
SHA256 edceaebe3d0e7a5d8d290a5396e39385886dc2840c1b74e39d32001f02af06cc
MD5 e51ff225ba2a72b73f1024e6ec8526bc
BLAKE2b-256 f9697dc1fde270c4cccecffd023ece48a8d5779d6ec625c9f155e426e1c39eeb

See more details on using hashes here.

Provenance

The following attestation bundles were made for container_magic-5.6.0.tar.gz:

Publisher: ci.yml on markhedleyjones/container-magic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file container_magic-5.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for container_magic-5.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 496ad358174f04003242535db667e32484fbd88cd806e357c4fb30066dd39d85
MD5 a20b2eaad770d4d45ca72f1947e7d3f2
BLAKE2b-256 82683ce464a6a2f3013ac44bb651cf7967694ebe0509c01d543b98c7fc6c073d

See more details on using hashes here.

Provenance

The following attestation bundles were made for container_magic-5.6.0-py3-none-any.whl:

Publisher: ci.yml on markhedleyjones/container-magic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page