Poetry Dockerize Plugin
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.tomlconfiguration file.
Installation
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@latest
Quickstart
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!
Usage in GitHub Actions
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@latest
- 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
Configuration via pyproject.toml
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"
Configuration via environment variables
You can also pass any option via environment variable by prefixing the key with DOCKERIZE_. For example, to set the entrypoint you can use the DOCKERIZE_ENTRYPOINT environment variable:
export DOCKERIZE_ENTRYPOINT="python -m myapp"
poetry dockerize
or use a .env file which will be loaded by the plugin:
echo "DOCKERIZE_ENTRYPOINT=python -m myapp" > .env
poetry dockerize
For dicts such as env and labels, you can set multiple values by adding multiple variables:
export DOCKERIZE_ENV_MY_VAR="my_value"
export DOCKERIZE_ENV_MY_OTHER_VAR="my_other_value"
export DOCKERIZE_LABELS_MY_LABEL="label1"
poetry dockerize
Configuration API Reference
This examples shows a complete configuration of the docker image:
[tool.dockerize]
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-run-instructions = ["RUN curl https://huggingface.co/transformers/"]
# Only for build docker layer
build-apt-packages = ["gcc"]
extra-build-instructions = ["RUN poetry config http-basic.foo <username> <password>"]
build-poetry-install-args = ["-E", "all", "--no-root"]
namecustomizes the docker image name.pythonpython version to use. If not specified, will try to be extracted fromtool.poetry.dependencies.python. Default is3.11base-imagecustomizes the base image. If not defined, the default base image ispython:<python-version>-slim-bookworm.tagsdeclares a list of tags for the image.entrypointcustomizes the entrypoint of the image. If not provided, the default entrypoint is retrieved from thepackagesconfiguration.portsexposes portsenvdeclares environment variables inside the docker image.labelsappend labels to the docker image. Default labels are added following the opencontainers specification.apt-packagesinstalls apt packages inside the docker image.extra-run-instructionsadds extra instructions to the docker run (after poetry install). Any modification to the filesystem will be kept after the poetry install.
For the build step:
build-apt-packagesinstalls apt packages inside the build docker container.extra-build-instructionsadds 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.build-poetry-install-argsadds additional arguments to thepoetry installcommand in the build step.
Command line options
All command line options provided by the poetry-dockerize-plugin may be accessed by typing:
poetry dockerize --help
Troubleshooting
To troubleshoot the plugin, you can use the --debug flag to get more information about the execution.
poetry dockerize --debug
Generate Dockerfile
To only generate the Dockerfile, you can use the --generate flag.
poetry dockerize --generate
Then you can store the Dockerfile on the repository and use it as a template and customize it as you need.
License
This project is licensed under the terms of the MIT license.
Metadata
Release files for poetry-dockerize-plugin 1.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| poetry_dockerize_plugin-1.3.1.tar.gz | 10.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| poetry_dockerize_plugin-1.3.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.5 kB
Release files / poetry_dockerize_plugin-1.3.1.tar.gz
| Download URL | poetry_dockerize_plugin-1.3.1.tar.gz |
|---|---|
| Size | 10.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ab8a1adafb24645bb1efca6d45fa9bd01c9237bc2696ba65d499ff8c98b3a615
|
|
BLAKE2b-256 checksum How to use checksums |
3c977ad18ec1bc2489970588f975875b7237a8c0cc635aedb90fe4c91a1825f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / poetry_dockerize_plugin-1.3.1-py3-none-any.whl
| Download URL | poetry_dockerize_plugin-1.3.1-py3-none-any.whl |
|---|---|
| Size | 10.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
828de3825017e713adf229525ad08fbf0c42b23a9deca83e88faf17b241469d1
|
|
BLAKE2b-256 checksum How to use checksums |
7ff30e53432816802ed4530950b70cda94458e2f3ae4ec034be0cf77fb1e532f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|