Key features:
- Automatically generate a docker image from your Poetry application.
- Highly configurable. You can configure the image by adding a section in the
pyproject.toml
configuration file.
In order to install the plugin you need to have installed a poetry version >=1.2.0
and type:
poetry self add poetry-dockerize-plugin
No configuration needed! Just type:
poetry dockerize
>Building image: poetry-sample-app:latest
>Successfully built image: poetry-sample-app:latest
docker run --rm -it poetry-sample-app:latest
>hello world!
You just need to run the quickstart command in your GitHub Actions workflow:
name: Build and publish latest
on:
push:
branches: main
jobs:
login:
runs-on: ubuntu-latest
steps:
- name: Install Poetry
uses: snok/install-poetry@v1
- name: Install poetry-dockerize-plugin
run: poetry self add poetry-dockerize-plugin
- name: Build and package
run: |
poetry install
poetry run pytest
poetry dockerize
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push to Docker Hub
run: docker push my-app:latest
To customize some options, you can add a [tool.dockerize]
section in your pyproject.toml
file. For example to change the image name:
[tool.dockerize]
name = "myself/myproject-app"
This examples shows a complete configuration of the docker image:
[tool.docker]
name = "alternative-image-name"
python = "3.12"
base-image = "python:3.12-slim"
tags = ["latest-dev"]
entrypoint = ["python", "-m", "whatever"]
ports = [5000]
env = {"MY_APP_ENV" = "dev"}
labels = {"MY_APP_LABEL" = "dev"}
apt-packages = ["curl"]
extra-build-instructions = ["RUN poetry config http-basic.foo <username> <password>"]
extra-run-instructions = ["RUN curl https://huggingface.co/transformers/"]
name
customizes the docker image name.python
python version to use. If not specified, will try to be extracted fromtool.poetry.dependencies.python
. Default is3.11
base-image
customizes the base image. If not defined, the default base image ispython:<python-version>-slim-buster
.tags
declares a list of tags for the image.entrypoint
customizes the entrypoint of the image. If not provided, the default entrypoint is retrieved from thepackages
configuration.ports
exposes portsenv
declares environment variables inside the docker image.labels
append labels to the docker image. Default labels are added following the opencontainers specification.apt-packages
installs apt packages inside the docker image.extra-build-instructions
adds extra instructions to the docker build (before poetry install). Any modification to the filesystem will be lost after the poetry install. If you need to add files to the image, use theextra-run-instructions
.extra-run-instructions
adds extra instructions to the docker run (after poetry install). Any modification to the filesystem will be kept after the poetry install.
All command line options provided by the poetry-dockerize-plugin
may be accessed by typing:
poetry dockerize --help
To troubleshoot the plugin, you can use the --debug
flag to get more information about the execution.
poetry dockerize --debug
This project is licensed under the terms of the MIT license.