Can you give me an example of a Dockerfile in which I can install all the packages I need from poetry.lock and pyproject.toml into my image/container from Docker?
12 Answers
There are several things to keep in mind when using poetry together with docker.
Installation
Official way to install poetry is via:
curl -sSL | python -
This way allows poetry and its dependencies to be isolated from your dependencies. But, in my point of view, it is not a very good thing for two reasons:
poetryversion might get an update and it will break your build. In this case you can specifyPOETRY_VERSIONenvironment variable. Installer will respect it- I do not like the idea to pipe things from the internet into my containers without any protection from possible file modifications
So, I use pip install 'poetry==$POETRY_VERSION'. As you can see, I still recommend to pin your version.
Also, pin this version in your pyproject.toml as well:
[build-system]
# Should be the same as `$POETRY_VERSION`:
requires = ["poetry>=1.0"]
build-backend = "poetry.masonry.api"
It will protect you from version mismatch between your local and docker environments.