docker/python Plugin

Copy Markdown View Source

Adds a Python venv to the generated Docker image of a release. Useful when an Elixir release shells out to Python tools (data science libraries, CLI tools, ML inference, etc.) and you want them available inside the container with a reproducible set of pinned packages.

Optional. Enable by listing Marea.Plugins.Docker.Python under plugins: in marea.yaml (the module-name spelling of docker.python). Pulls in Marea.Plugins.Docker transitively. No CLI commands of its own — the plugin only contributes a schema field and hooks into the Dockerfile-rendering chain.

Schema contributions

  • deploys.<d>.releases.<r>.docker.python: — release-level Python config, nested inside the Docker plugin's docker: block.
FieldTypeNotes
versionstringPython version label (currently informational; the venv uses whatever python3 is in the Alpine builder).
requirementslist of stringsPackage specifiers passed to uv pip install. Each entry is one specifier (e.g. "requests==2.31.0", "flask>=3.0").

How the venv gets into the image

docker.python implements Marea.Plugins.Docker.marea_dockerfile_assigns/2, the hook Marea.Plugins.Docker runs before rendering the Dockerfile. When the active release has a docker.python: block, the plugin appends two fragments to the assigns:

  • :extra_stages gets a new python-builder Alpine stage that installs python3, downloads uv as a static binary, runs uv venv /opt/venv --python python3, and uv pip installs the requirements.
  • :extra_app_steps gets a COPY --from=python-builder /opt/venv /opt/venv plus an apk add --no-cache python3 and a chown -R app inside the final app stage.

The built-in Dockerfile template (priv/templates/docker/dockerfile_v01.eex) expands those extension points; project-local templates that override the default need to do the same if they want Python support to keep working. See docker.md for the extension-point contract.

Example

plugins:
  - Marea.Plugins.Helm           # pulls in Docker + Build via plugin_deps
  - Marea.Plugins.Docker.Python  # pulls in Docker via plugin_deps

deploys:
  staging:
    helm:
      namespace: my-app-staging
    releases:
      api:
        helm:
          template: deployment.yaml
        docker:
          python:
            requirements:
              - "requests==2.31.0"
              - "flask>=3.0"

marea build show-dockerfile --deploy staging --release api shows the Python build stage and app-stage venv copy injected into the default Dockerfile.

Source