Skip to content

Local development

Complete guide for using pycontainer-build locally during development, including installation, building images, testing, and troubleshooting.

Dependency staging uses a mapped release, explicit base image PYTHON_LIBC, or effective package metadata from verified official tag-only base layers. Codename-less automatic/default Python images remain supported when that evidence is valid. Missing or unsupported evidence fails before pip; then use --base-image python:3.11-slim-bookworm (or a mapped release for your Python version) or provide supported base metadata. No libc floor is guessed.


The recommended way for local development:

Terminal window
# Clone the repository
git clone https://github.com/spboyer/pycontainer-build.git
cd pycontainer-build
# Create the project environment with locked development tools
uv sync --locked --group test --group build

This installs the core package in editable mode with locked test and build tools. The core package itself continues to declare no runtime dependencies. Activate the environment for the CLI examples below:

.\.venv\Scripts\Activate.ps1
source .venv/bin/activate
Terminal window
# Check that the command is available
uv run --locked --group test --group build pycontainer --help
# Verify the Python API works
uv run --locked --group test --group build python -c "from pycontainer.builder import ImageBuilder; print('Import successful')"

Terminal window
# Build from the current directory
pycontainer build --tag myapp:latest
# Build from a specific directory
pycontainer build --tag myapp:latest --context /path/to/project
# Build with verbose output
pycontainer build --tag myapp:latest --verbose

By default, images are created at:

<context-path>/dist/image/
├── index.json # OCI index (manifest list)
├── oci-layout # Version marker
├── blobs/sha256/
│ ├── <manifest-digest> # Manifest blob
│ ├── <config-digest> # Config blob
│ ├── <base-layer-digests> # Base image layers (if using --base-image)
│ └── <app-layer-digest> # Application layer (tar)
└── refs/tags/
└── myapp:latest # Tag reference
Terminal window
# Select a mapped release for dependency staging
pycontainer build \
--tag myapp:latest \
--base-image python:3.11-slim-bookworm \
--include-deps
# Or explicitly specify a base image
pycontainer build \
--tag myapp:latest \
--base-image python:3.12-slim-bookworm \
--include-deps
# Build for different platform (e.g., amd64 from ARM Mac)
pycontainer build \
--tag myapp:amd64 \
--base-image python:3.11-slim-bookworm \
--platform linux/amd64 \
--include-deps
# Build for ARM64 (e.g., for AWS Graviton instances)
pycontainer build \
--tag myapp:arm64 \
--base-image python:3.11-slim-bookworm \
--platform linux/arm64 \
--include-deps
# This will:
# 1. Pull python:3.11-slim-bookworm layers from registry
# 2. Package your app files
# 3. Include pip-installed dependencies
# 4. Combine everything into a complete image

The single dependency layer is the default. To opt in for a target-selected uv.lock, assign distribution names explicitly:

Terminal window
pycontainer build --tag myapp:latest --include-deps \
--dependency-layer-strategy explicit \
--stable-dependency numpy --frequent-dependency my-package

Alternatively, use --dependency-layer-strategy history with an optional --dependency-history-ref REF. The build reports the resolved commit and classification evidence. Explicit --stable-dependency and --frequent-dependency options override history; otherwise, absent or changed target versions are frequent. Each historical lock graph is evaluated with the target’s markers and selected dependency extras; an unsupported or ambiguous target graph fails explicitly. History requires Git, a tracked clean lock, a complete non-shallow/non-partial repository, and at least two distinct lock snapshots. Ungrouped or shared transitives are frequent in explicit mode.

Only uv.lock is supported for grouping. Requirements, virtualenvs and other lock formats fail explicitly; they remain available with the default single layer. A complete group-cache hit avoids pip and package-index requests. A changed lock stages and verifies the full selection again; an unchanged group can reuse its cached layer when the full manifest roots are unchanged. --strip-type-stubs removes typing-only files before grouping, and --squash can flatten the resulting layers. See the README for TOML settings and ownership limitations.

Conda staging is unsupported. Detection checks names only: environment.yml, environment.yaml, conda-lock.yml, and conda-meta/ directories anywhere in the selected build context. It does not parse YAML, run Conda, or inspect the active host environment. Ordinary directories are checked independently of application include paths; excluded tests, fixtures, generated output/cache directories, and explicitly excluded descendants do not trigger it. Conventional virtualenv directories and linked Conda prefixes are checked. Directory links are otherwise traversed only when selected as application include roots, matching application file selection.

With --include-deps, detected Conda inputs without a supported selected lock or pip requirements file raise an explicit error before pulling the base image, also in dry-run. An explicitly selected or auto-detected supported lock takes precedence over a virtualenv; otherwise a pip requirements file takes precedence. A warning explains that Conda inputs are ignored. --requirements remains relative to the context and can select an exported file excluded from the application layer. Selecting a Conda YAML file as pip requirements, including via a file link, is rejected rather than passed to pip. Selected source paths inside a host Conda prefix are omitted; with --include-deps they also produce a Conda diagnostic unless the marker is excluded. Selected lockfiles and requirements inside a host prefix are rejected.

Export the pip-compatible portion from your Conda environment, then build from your application source directory:

Terminal window
python -m pip freeze > requirements.txt
python -m pycontainer.cli build --tag myapp:latest --include-deps --requirements requirements.txt

Review the export: remove host-local paths and ensure requirements resolve to target-compatible wheels. pip freeze is not a conversion of Conda-only packages or native/system libraries; provide those in a compatible base image. No YAML resolution or full Conda staging is implemented; that work is tracked in #187.

Without --include-deps, a source project containing Conda descriptors still builds application-only, without dependency warnings or installation. Nested host Conda prefixes (directories containing conda-meta/) are always omitted from application and virtualenv dependency selection, including explicit includes and --no-default-excludes. A context that is itself a host Conda prefix or is inside one is rejected: choose a source-only context instead of the environment directory. This protects against copying host binaries, not a guarantee that an application-only image has all dependencies needed to run.

Terminal window
# Dry-run mode - see what will be built without creating files
pycontainer build --tag myapp:latest --dry-run --verbose

This shows:

  • Detected entry point
  • Files that will be included
  • Base image layers (if applicable)
  • Final image configuration

Important: pycontainer creates OCI-compliant image layouts in dist/image/. These are not directly runnable by Docker without importing. See the options below for testing your built images.

Section titled “Option 1: Use Skopeo (Recommended for OCI Layouts)”

Skopeo is the proper tool for working with OCI image layouts and can copy them directly to Docker:

Terminal window
# Install skopeo
# macOS:
brew install skopeo
# Ubuntu/Debian:
sudo apt-get install skopeo
# Fedora/RHEL:
sudo dnf install skopeo
# 1. Build the image with pycontainer
pycontainer build --tag myapp:latest --base-image python:3.11-slim-bookworm --include-deps
# 2. Copy the OCI layout to Docker daemon
skopeo copy oci:dist/image docker-daemon:myapp:latest
# 3. Run the container
docker run -p 8000:8000 myapp:latest
# Alternative: Copy to a registry
skopeo copy oci:dist/image docker://localhost:5000/myapp:latest

Podman natively supports OCI layouts without conversion:

Terminal window
# Install Podman
# macOS:
brew install podman
podman machine init
podman machine start
# Ubuntu/Debian:
sudo apt-get install podman
# Fedora/RHEL (included by default):
sudo dnf install podman
# 1. Build with pycontainer
pycontainer build --tag myapp:latest --base-image python:3.11-slim-bookworm --include-deps
# 2. Run directly from the OCI layout
podman run --rm -p 8000:8000 oci:dist/image:myapp
# Or import into Podman's local storage
skopeo copy oci:dist/image containers-storage:localhost/myapp:latest
podman run -p 8000:8000 localhost/myapp:latest

If you only have Docker and can’t install skopeo:

Terminal window
# 1. Build the image with pycontainer
pycontainer build --tag myapp:latest --base-image python:3.11-slim-bookworm --include-deps
# 2. Create a tar archive and import (less efficient)
tar -C dist/image -czf - . | docker import - myapp:latest
# Note: This creates a single-layer image and loses metadata
# For proper testing, use skopeo (Option 1) instead
# 3. Run the container
docker run -p 8000:8000 myapp:latest
Terminal window
# Build with pycontainer
pycontainer build --tag myapp:latest --base-image python:3.11-slim-bookworm --include-deps
# Import into Podman
podman load -i <(tar -C dist/image -cf - .)
# Run with Podman
podman run -p 8000:8000 myapp:latest

Run a local registry for testing across tools:

Terminal window
# Start a local registry (Docker or Podman required)
docker run -d -p 5000:5000 --name registry registry:2
# OR
podman run -d -p 5000:5000 --name registry docker.io/library/registry:2
# Build and push to local registry
pycontainer build \
--tag localhost:5000/myapp:latest \
--base-image python:3.11-slim-bookworm \
--include-deps \
--push
# Pull and run from local registry
docker pull localhost:5000/myapp:latest
docker run -p 8000:8000 localhost:5000/myapp:latest
# Or with Podman:
podman pull localhost:5000/myapp:latest
podman run -p 8000:8000 localhost:5000/myapp:latest
# Clean up when done
docker stop registry && docker rm registry
# OR
podman stop registry && podman rm registry

For pure Python testing (no container runtime needed):

Terminal window
# Just run your app directly with Python
cd /path/to/your/app
pip install -r requirements.txt
python -m app # or uvicorn app.main:app, etc.

Key Concept: pycontainer creates OCI image layouts, not Docker-specific images.

Format What is it? Tools that understand it
OCI Layout Standard directory structure (dist/image/) Podman, skopeo, buildah, containerd
Docker Image Docker daemon’s internal format Docker only
Docker Archive Tar file with Docker-specific metadata Docker only
OCI Tarball Tar file with OCI layout Most tools

Why this matters:

  • Docker requires importing/converting OCI layouts before use
  • Podman can use OCI layouts directly
  • Skopeo is the bridge between OCI and Docker formats

Best practices:

  • Local testing: Use Podman or skopeo for native OCI support
  • CI/CD: Push to a registry; most tools pull from registries seamlessly
  • Production: Always use registries (GHCR, ACR, Docker Hub, etc.)

Terminal window
# 1. Make code changes to pycontainer-build
vim src/pycontainer/builder.py
# 2. Test with a sample project
cd examples/fastapi-app
pycontainer build --tag test:latest --verbose --dry-run
# 3. Build a real image
pycontainer build --tag test:latest --base-image python:3.11-slim-bookworm --include-deps
# 4. Test the image
docker load -i <(tar -C dist/image -cf - .)
docker run -p 8000:8000 test:latest
curl http://localhost:8000
# 5. Iterate - changes to pycontainer source are live (editable install)

The examples/ directory contains ready-to-use test projects:

Terminal window
# FastAPI example
cd examples/fastapi-app
pycontainer build --tag fastapi-test:latest --base-image python:3.11-slim-bookworm --include-deps --verbose
# Test the output structure
tree dist/image
# Inspect the manifest
cat dist/image/index.json | jq .

Python matrix configuration and publication

Section titled “Python matrix configuration and publication”
Terminal window
python -m pycontainer.cli build --python-version 3.11,3.12 --default-python-version 3.12 --tag myapp:v1.2.3 --latest --semver-tags --output dist\matrix --dry-run

CLI --python-version overrides TOML python_versions (a list of minor-version strings). --default-python-version overrides default_python_version; when omitted, the first version receives unsuffixed aliases. --output overrides output_dir. Each layout is isolated under <output_dir>/pyX.Y, with no top-level index combining Python versions. The whole output parent is excluded from application inputs, including sibling version layouts.

[build]
tag = "myapp:v1.2.3"
python_versions = ["3.11", "3.12"]
default_python_version = "3.12"
output_dir = "dist/matrix"
platform = "linux/amd64,linux/arm64"
latest_tag = true
semver_tags = true
[build.python_matrix]
"3.11" = "oci:fixtures/python-eleven"
"3.12" = "registry.example/team/python:twelve"

An unpinned official minor tag such as python:3.11-slim can supply the matrix automatically by rewriting its minor and retaining -slim. All other bases require the explicit version map. The pulled base metadata, not an application environment override, must establish the requested PYTHON_VERSION for each platform; custom bases also provide PYTHON_IMPLEMENTATION=CPython.

With --include-deps, each minor and platform resolves its own lockfile markers and hash-pinned wheels. Lock staging needs a full base PYTHON_VERSION such as 3.11.9 and a matching wheel for each selected package. Digest-pinned and local bases need explicit Python and libc metadata.

Signing, provenance attestation, and build --validate are not supported for matrices. Unsigned provenance with single dependency layers is written separately for each version; validate each resulting layout separately with pycontainer validate image. Grouped dependency layers with provenance are rejected for matrices. pycontainer preview also requires a single-version configuration rather than a matrix.

Explicit tags are suffixed -py3.11/-py3.12; unsuffixed tags and generated semver/latest aliases belong only to the default version. Adding --push builds and integrity-verifies all layouts first, prepares all remote blobs and manifests/indexes by digest, then publishes version tags followed by aliases. Root and per-version output locks are held during the build and verification, then reacquired for verification and publication. Failures stop immediately with confirmed/failed/unknown/unattempted operation reporting, even with --no-progress. Remote tag updates are non-atomic: previous updates or untagged uploaded content may remain. Ambiguous writes are unknown, never assumed unchanged. There is no rollback, deletion or retry-overwrite, which could destroy a concurrent writer’s update.

For Python API callers, ImageBuilder.push(registry_url="mirror.example/team/app:v9") changes the destination repository and primary tag, returning that normalized reference. Matrix version tags use v9-pyX.Y; the unsuffixed v9 belongs to the default version. Configured additional tags and generated aliases are retained at the destination, as in non-matrix pushes, without regenerating semver aliases from the override. Local layout tags remain unchanged. Invalid generated tags or version/alias collisions fail before any remote publication.

Python matrices reject vulnerability scanning and Git-derived tags (tag_from_git) at configuration and again before build or publication; set an explicit tag or build each Python version separately.

Hermetic tests do not establish real per-version/per-architecture startup.

Declared build arguments expand once before matrix layouts are derived. Each child preserves literal dollar expressions and the parent’s diagnostic redaction and cache context; version suffixes are applied to the resolved tags.

Terminal window
# Create a test config file
cat > pycontainer.toml << EOF
[build]
base_image = "python:3.11-slim"
workdir = "/app"
include_deps = true
[build.env]
DEBUG = "true"
PORT = "8000"
[build.labels]
maintainer = "you@example.com"
version = "dev"
EOF
# Build with the config
pycontainer build --tag myapp:dev --config pycontainer.toml --verbose
# Verify the config was applied
jq '.config' dist/image/blobs/sha256/<config-digest>
Terminal window
# See what entry point is detected
pycontainer build --tag myapp:latest --dry-run --verbose | grep -i "entry"
# Override with explicit entry point
cat > pycontainer.toml << 'EOF'
[build]
entrypoint = ["python", "-m", "myapp.cli"]
EOF
pycontainer build --tag myapp:latest --config pycontainer.toml
Terminal window
# Generate SPDX SBOM
pycontainer build --tag myapp:latest --sbom spdx --verbose
# Check the SBOM was created
ls -lh dist/image/sbom.json
# View the SBOM
cat dist/image/sbom.json | jq '.packages[].name'

Use Case 4: Testing Framework Auto-Detection

Section titled “Use Case 4: Testing Framework Auto-Detection”
Terminal window
# FastAPI project
cd examples/fastapi-app
pycontainer build --tag test:latest --dry-run --verbose
# Should show: "Detected framework: fastapi"
# Flask project (create test)
mkdir test-flask && cd test-flask
cat > app.py << 'EOF'
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello from Flask!'
EOF
echo '[project]\nname="flask-test"\nversion="0.1.0"' > pyproject.toml
pycontainer build --tag flask-test:latest --dry-run --verbose
# Should show: "Detected framework: flask"

For Celery, Jupyter, Streamlit, and Gradio detection, including precedence, ambiguous entrypoints, and Jupyter authentication, see Framework detection.

Terminal window
# First build (cold cache)
time pycontainer build --tag myapp:v1 --base-image python:3.11-slim-bookworm --include-deps
# Second build (warm cache - should be faster)
time pycontainer build --tag myapp:v2 --base-image python:3.11-slim-bookworm --include-deps
# Check cached blobs
ls -lh ~/.pycontainer/cache/blobs/sha256/
# Force rebuild without cache
pycontainer build --tag myapp:v3 --base-image python:3.11-slim-bookworm --include-deps --no-cache
Terminal window
# Build for AMD64 from your ARM Mac
pycontainer build \
--tag myapp:amd64 \
--platform linux/amd64 \
--base-image python:3.11-slim-bookworm \
--include-deps \
--verbose
# Verify the platform in the image config
MANIFEST_DIGEST=$(jq -r '.manifests[0].digest' dist/image/index.json | cut -d: -f2)
CONFIG_DIGEST=$(jq -r '.config.digest' dist/image/blobs/sha256/$MANIFEST_DIGEST | cut -d: -f2)
jq '.architecture, .os' dist/image/blobs/sha256/$CONFIG_DIGEST
# Output: "amd64" "linux"
# Build for ARM64 (AWS Graviton, Raspberry Pi, etc.)
pycontainer build \
--tag myapp:arm64 \
--platform linux/arm64 \
--base-image python:3.11-slim-bookworm \
--include-deps
# Build one OCI image index for both platforms and push it under one tag
pycontainer build \
--tag ghcr.io/user/myapp:v1 \
--platform linux/amd64,linux/arm64 \
--push
# Add 32-bit ARM (exact arm/v7 variant). With --include-deps, every
# requirement needs an armv7l wheel; there is no source-build fallback.
pycontainer build \
--tag ghcr.io/user/myapp:v1 \
--platform linux/amd64,linux/arm64,linux/arm/v7 \
--push

Terminal window
# Pretty-print the index
jq '.' dist/image/index.json
# Find the manifest digest
MANIFEST_DIGEST=$(jq -r '.manifests[0].digest' dist/image/index.json | cut -d: -f2)
# View the manifest
jq '.' dist/image/blobs/sha256/$MANIFEST_DIGEST
Terminal window
# Get config digest from manifest
CONFIG_DIGEST=$(jq -r '.config.digest' dist/image/blobs/sha256/$MANIFEST_DIGEST | cut -d: -f2)
# View the config
jq '.' dist/image/blobs/sha256/$CONFIG_DIGEST
Terminal window
# Get layer digest
LAYER_DIGEST=$(jq -r '.layers[0].digest' dist/image/blobs/sha256/$MANIFEST_DIGEST | cut -d: -f2)
# Extract to temporary directory
mkdir -p /tmp/layer
tar -xzf dist/image/blobs/sha256/$LAYER_DIGEST -C /tmp/layer
# View contents
tree /tmp/layer
Terminal window
# Build with pycontainer
pycontainer build --tag myapp:pycontainer --base-image python:3.11-slim-bookworm --include-deps
# Build equivalent with Docker
cat > Dockerfile << EOF
FROM python:3.11-slim
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt
CMD ["python", "-m", "app"]
EOF
docker build -t myapp:docker .
# Compare sizes
du -sh dist/image
docker images myapp:docker --format "{{.Size}}"
# Compare manifests
docker save myapp:docker -o docker-image.tar
tar -xf docker-image.tar
cat manifest.json | jq .

Terminal window
# See detailed build progress
pycontainer build --tag myapp:latest --verbose
# Outputs:
# - Project detection results
# - File paths being included
# - Layer creation progress
# - Registry push details (if --push)
# - Cache hits/misses

Solution: Explicitly specify the entrypoint in pycontainer.toml:

[build]
entrypoint = ["python", "-m", "myapp"]

Then run pycontainer build --tag myapp:latest --config pycontainer.toml.

Solution: Check registry authentication:

Terminal window
# For Docker Hub
docker login
# For GHCR
echo $GITHUB_TOKEN | docker login ghcr.io -u USERNAME --password-stdin
# For ACR
az acr login --name myregistry
# Then build
pycontainer build --tag myapp:latest --base-image python:3.11-slim

For offline or air-gapped builds, load the base image from disk instead of a registry; no credentials or daemon are used:

Terminal window
skopeo copy docker://python:3.11-slim oci:./base:3.11-slim # or: docker save python:3.11-slim -o python.tar
pycontainer build --tag myapp:latest --base-image oci:./base:3.11-slim
pycontainer build --tag myapp:latest --base-image docker-archive:./python.tar:python:3.11-slim

For --include-deps, the local image config must explicitly declare PYTHON_IMPLEMENTATION=CPython, PYTHON_VERSION, and a supported PYTHON_LIBC, even when its tag claims an official Python image. See Local base images for selection rules, verification, and limitations.

Issue: “Dependencies not found in image”

Section titled “Issue: “Dependencies not found in image””

Solution: Ensure --include-deps and dependencies are installed:

Terminal window
# Install dependencies first
pip install -r requirements.txt
# Then build with --include-deps
pycontainer build --tag myapp:latest --base-image python:3.11-slim-bookworm --include-deps

Issue: “Permission denied writing to dist/”

Section titled “Issue: “Permission denied writing to dist/””

Solution: Check write permissions:

Terminal window
# Check permissions
ls -ld dist/
# Fix permissions
chmod -R u+w dist/
# Or use a different output directory
pycontainer build --tag myapp:latest --output /tmp/myimage

Solution: Clear cache and rebuild:

Terminal window
# Remove cache
rm -rf ~/.pycontainer/cache
# Rebuild
pycontainer build --tag myapp:latest --no-cache

For deeper debugging, use the Python API:

from pycontainer.config import BuildConfig
from pycontainer.builder import ImageBuilder
import logging
# Enable debug logging
logging.basicConfig(level=logging.DEBUG)
# Create config
config = BuildConfig(
tag="myapp:debug",
context_dir=".",
base_image="python:3.11-slim",
include_deps=True,
verbose=True
)
# Build and catch exceptions
try:
builder = ImageBuilder(config)
builder.build()
except Exception as e:
print(f"Build failed: {e}")
import traceback
traceback.print_exc()

The synthetic benchmark uses local hashed wheels, a loopback package index and a loopback registry. Run it from the repository root:

Terminal window
python benchmarks\run_build_benchmarks.py --grouped-only --repetitions 3 --files 1000 --file-bytes 1024 --output grouped-benchmark.json

Each cold sample starts with empty local and registry caches. Warm, app-change and frequent-dependency-change samples each start from a copy of the same baseline cache and registry blobs. The JSON includes layer digests and sizes, cache hits, installer and package-index requests, registry HEAD/PUT counts, received blob bytes, build and layer-upload times, process peak RSS and Python tracemalloc peak. The operating-system page cache is not controlled; the RSS measurement is taken after the build, before registry push, and excludes pip child processes. Upload measurements exclude config, manifest and protocol bytes. The base image is synthetic: no external registry transfer or container startup is measured. These observations are not end-to-end performance claims or timing gates.


Terminal window
# 1. Use cache (enabled by default)
pycontainer build --tag myapp:latest --base-image python:3.11-slim-bookworm --include-deps
# 2. Use smaller base images
pycontainer build --tag myapp:latest --base-image python:3.11-alpine3.20 --include-deps
# 3. Include only necessary files
pycontainer build \
--tag myapp:latest \
--include src/ \
--include pyproject.toml \
--include requirements.txt
Terminal window
# Use distroless for smaller images
pycontainer build --tag myapp:latest --base-image gcr.io/distroless/python3-debian11
# Or use Alpine
pycontainer build --tag myapp:latest --base-image python:3.11-alpine
# Don't include unnecessary dependencies
pip install --no-dev -r requirements.txt
pycontainer build --tag myapp:latest --base-image python:3.11-slim-bookworm --include-deps

Terminal window
# 1. Install the VS Code extension
code --install-extension ms-python.pycontainer
# 2. Open your project in VS Code
code /path/to/project
# 3. Use Command Palette (Cmd+Shift+P):
# - "pycontainer: Build Container Image"
# - "pycontainer: Build and Push Container Image"

Follow the Poetry plugin guide to install from this repository checkout.

Terminal window
# Build container
cd /path/to/poetry/project
poetry build-container --tag myapp:latest
# Configuration via pyproject.toml
[tool.pycontainer]
base_image = "python:3.11-slim"
include_deps = true
push = false

Follow the Hatch plugin guide to install from this repository checkout.

Terminal window
# Build (creates both wheel and container)
cd /path/to/hatch/project
hatch build
# Configuration via pyproject.toml
[tool.hatch.build.hooks.pycontainer]
base_image = "python:3.11-slim"
include_deps = true

Try these ready-made examples:

Terminal window
cd examples/fastapi-app
# Quick build
pycontainer build --tag fastapi-demo:latest --base-image python:3.11-slim-bookworm --include-deps --verbose
# Test locally
docker load -i <(tar -C dist/image -cf - .)
docker run -p 8000:8000 fastapi-demo:latest
curl http://localhost:8000
Terminal window
# Create a minimal test
mkdir minimal-test && cd minimal-test
cat > app.py << 'EOF'
print("Hello from pycontainer!")
EOF
cat > pyproject.toml << 'EOF'
[project]
name = "minimal-test"
version = "0.1.0"
EOF
# Build
pycontainer build --tag minimal:latest --verbose
# Inspect
tree dist/image


  1. Always use --verbose during development to understand what’s happening
  2. Use --dry-run to preview builds before creating artifacts
  3. Test with multiple base images (slim, alpine, distroless) to find the best fit
  4. Keep pycontainer.toml in your project for consistent builds
  5. Use cache for faster iterations (don’t disable unless debugging cache issues)
  6. Version your images with meaningful tags (not just latest)
  7. Generate SBOMs for security compliance (--sbom spdx)
  8. Use reproducible builds for consistent outputs (--reproducible, enabled by default)


Happy building! 🐍🐳