Skip to content

Your first image

pycontainer builds an OCI image layout from a Python project without a Dockerfile or a Docker daemon. It can also push that image to a registry. Building does not start your application; running an image still needs a container runtime.

The project is experimental. Start with a small application and review images and dependencies before staging packages.

Use Python 3.11 or newer. Install a released version:

Terminal window
pip install pycontainer-build
# Or use an isolated CLI tool environment
uv tool install pycontainer-build
pycontainer --help

To try the repository examples below, also get a source checkout. For an editable source install instead of a release:

Terminal window
git clone https://github.com/spboyer/pycontainer-build.git
cd pycontainer-build
python -m pip install --no-deps -e .
pycontainer --help

For contributor tooling, use uv sync --locked --group test --group build instead. If you do not activate that environment, prefix commands with uv run --locked --group test --group build.

The repository includes a FastAPI application. Preview its configuration without pulling a base image or building layers:

Terminal window
pycontainer build --context examples/fastapi-app --tag demo:local --dry-run

For your own project, run pycontainer init --template fastapi --app main:app from its directory. The template writes configuration, not application code. See configuration templates for Flask and generic projects.

Terminal window
pycontainer build --context examples/fastapi-app --tag demo:local --base-image python:3.11-slim-bookworm --include-deps

This pulls the base image and stages the example’s dependencies. It needs network access and pip in the builder’s Python environment. Wheel-only staging is not cross-compilation; unsupported packages fail rather than falling back to source builds.

The output is under the build context: examples/fastapi-app/dist/image/. It contains oci-layout, index.json, content-addressed blobs and tag references. It is not a Docker archive.

Inspect the output offline:

Terminal window
pycontainer validate image --output examples/fastapi-app/dist/image

Validation checks OCI structure and image metadata. It does not prove that the application starts.

With Skopeo installed and a running Docker daemon, import the layout and run it:

Terminal window
skopeo copy oci:examples/fastapi-app/dist/image docker-daemon:demo:local
docker run --rm -p 8000:8000 demo:local

Open http://localhost:8000. Docker is used here to run the result, not to build it. For further local workflows, see local development.

Use a registry repository you can write to:

Terminal window
pycontainer build --context examples/fastapi-app --tag ghcr.io/YOUR_USER/demo:latest --base-image python:3.11-slim-bookworm --include-deps --push

Do not put credentials in commands, configuration files or image layers. Follow registry authentication and publication for host-scoped authentication and transport rules.