uv
uv can install and run pycontainer-build as a global tool, as a one-off command, or as a project development dependency. uv is an external developer tool here: pycontainer-build still has no runtime dependencies and does not need uv to build images.
This guide is about running the builder itself. Staging an application’s
uv.lock dependencies into an image is covered under
staging Python dependencies.
Versions and pins
Section titled “Versions and pins”Always pin pycontainer-build to a release tag or a verified commit SHA, never a
moving branch such as main. A pin makes builds repeatable and lets you review
each upgrade.
- PyPI, from 0.4.0:
pycontainer-build==0.4.0. Earlier versions are not on PyPI. - Git tag:
git+https://github.com/spboyer/pycontainer-build@v0.4.0. - Git commit:
git+https://github.com/spboyer/pycontainer-build@<40-character SHA>. Use a full SHA you have reviewed, not an abbreviated one.
Version 0.4.0 is the first release with the pycontainer-build command alias
and python -m pycontainer. Every version installs the pycontainer command,
and python -m pycontainer.cli keeps working.
Global tool
Section titled “Global tool”Install once and run pycontainer from any directory:
# From PyPI, 0.4.0 or lateruv tool install pycontainer-build==0.4.0
# Or from a release taguv tool install git+https://github.com/spboyer/pycontainer-build@v0.4.0
pycontainer build --tag myapp:latestuv installs both pycontainer and pycontainer-build (0.4.0 or later) in its
tool bin directory. Run uv tool update-shell if that directory is not on
PATH. Upgrade by installing a new pin with --force, and remove the tool
with uv tool uninstall pycontainer-build.
One-off runs with uvx
Section titled “One-off runs with uvx”uvx runs the builder in a temporary, cached environment without installing
it:
# From PyPI, 0.4.0 or lateruvx --from pycontainer-build==0.4.0 pycontainer-build build --tag myapp:latest
# From a release taguvx --from git+https://github.com/spboyer/pycontainer-build@v0.4.0 pycontainer build --tag myapp:latestThe distribution is named pycontainer-build, so from 0.4.0 the matching
pycontainer-build command lets uvx find it by name. Keep --from with an
explicit version: without one, uvx resolves the latest release whenever its
cache refreshes.
Project development dependency
Section titled “Project development dependency”Add the builder to a uv-managed project’s dev dependency group:
# From PyPI, 0.4.0 or lateruv add --dev pycontainer-build==0.4.0
# Or from a release taguv add --dev "pycontainer-build @ git+https://github.com/spboyer/pycontainer-build@v0.4.0"The git form records a [tool.uv.sources] entry. You can also write it by
hand:
[dependency-groups]dev = ["pycontainer-build"]
[tool.uv.sources]pycontainer-build = { git = "https://github.com/spboyer/pycontainer-build", tag = "v0.4.0" }Use rev = "<40-character SHA>" instead of tag to pin a verified commit.
Then run the builder through the project environment:
uv run pycontainer build --tag myapp:latestuv run -m pycontainer build --tag myapp:latest # 0.4.0 or laterBuild settings still come from the usual configuration. Put them in a
[tool.pycontainer] table in pyproject.toml, or a [build] table in
pycontainer.toml, and name the file with --config; command-line flags
override file values. uv does not read or change these settings.
The builder runs inside the project environment, which uv keeps in .venv.
The default excludes keep .venv out of the application layer. A builder in
the dev group is not a runtime dependency of the image.
See examples/uv-app for a complete project.
CI with GitHub Actions
Section titled “CI with GitHub Actions”Pin third-party actions by full commit SHA and the builder by version or tag:
jobs: image: runs-on: ubuntu-latest permissions: contents: read steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0 with: version: "0.13.6" - name: Build image layout run: uvx --from pycontainer-build==0.4.0 pycontainer-build build --tag myapp:${{ github.sha }}Before 0.4.0 is on PyPI, use the git form with a verified commit:
uvx --from git+https://github.com/spboyer/pycontainer-build@<40-character SHA> pycontainer build ....
For registry pushes and authentication, see GitHub Actions
and Authentication.
Windows
Section titled “Windows”The commands are the same in PowerShell. uv installs pycontainer.exe and
pycontainer-build.exe launchers. Quote requirement specifiers that contain
@ or spaces, as in the uv add --dev example.