Python Docker images that use poetry for dependency management.
50K+
A series of Python Docker images that use poetry for dependency management. Because this is what I tend to do, these images also:
tini for simple init.FROM duffn/python-poetry:3.9-slim
COPY pyproject.toml poetry.lock ./
# Poetry is installed with `pip`, so active our virtual environmentn and install projects dependecies there, so they don't conflict with poetry's dependencies.
RUN . $VENV_PATH/bin/activate && $POETRY_HOME/poetry install --no-root
WORKDIR /app
COPY . .
# Our user has an ID of 10000 and the group an ID of 10001.
RUN chown 10000:10001 -R /app
# Our non-root username.
USER nonroot
# Use `tini` to start our container.
ENTRYPOINT ["tini", "--"]
CMD ["./my-start-command.sh"]
FROM duffn/python-poetry:3.9-slim as base
COPY ./poetry.lock ./pyproject.toml ./
# Only install the production dependencies in our base multi-stage build.
RUN . $VENV_PATH/bin/activate && $POETRY_HOME/poetry install --no-root --no-dev
# Development image
FROM base as development
# Install the development dependencies as well in our development target.
RUN . $VENV_PATH/bin/activate && $POETRY_HOME/poetry install --no-root
WORKDIR /app
COPY . .
RUN chown 10000:10001 -R /app
USER nonroot
ENTRYPOINT ["tini", "--"]
CMD ["./my-start-command.sh"]
# Production image
# Build only a single target with the --target production flag.
# `docker build --target production -t my-image:latest .`
FROM base as production
# No need to install dependenices here as we have the production dependencies in our base image.
WORKDIR /app
COPY . .
RUN chown 10000:10001 -R /app
USER nonroot
ENTRYPOINT ["tini", "--"]
CMD ["./my-start-command.sh"]
my-start-command.sh could look something like:
#!/bin/bash
set -e
. /venv/bin/activate
flask run --host=0.0.0.0
All images use the official Python images as their base.
X.X-<name> tags, for example 3.9-slim should use the most recent version of poetry.poetry using the X.X-<name>-X.X.X tags, where X.X.X is a version of poetry starting with the minimum version of 1.1.4. For example, 3.9-slim-1.1.4.
Content type
Image
Digest
sha256:c34571752…
Size
83.7 MB
Last updated
almost 3 years ago
docker pull duffn/python-poetry:3.9.18-slim-1.6.1-2023-10-06