-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Official Docker containers? #4036
Comments
For question 2, |
That's great! I missed that, thank you. So with that, while I think official containers would be convenient they wouldn't add much and I understand if this is low / no priority. Feel free to close this issue if it's not on the roadmap. |
This might be relevant for anyone who comes across this issue: #1879 |
Are you open to PRs for this? I'm thinking of just adding another github actions workflow. |
The following approaches for doing this is available:
1 and 3 are probably the best options. If there is some support from this project for 1 then it may be a better option. Some things to think about there should likely be tags for each latest version poetry for each of the supported and maintained pythons, for each variant of python (slim, alpine, standard). |
Hi, I have been working with Poetry in Docker for over a year now. Today I thought that it would be handy to have a official Docker image for Poetry and after some searching I stumbled into this issue. I am willing to work on this, but the catch here is that this will be my first contribution on GitHub. I will need some help, because I do not even know how to start properly and how the workflow looks like. |
Bumping this. Would be awesome to have official images. Happy to contribute. |
I forked the repo and currently working on docker images. I am using the same tools and structure as the python official image. But my experiments raised some questions to be discussed:
Maintainers and concerned parties, please advise, and let's discuss. |
I don't really see the latter variant as consistently useful, neither as a maintainer of CI/CD nor as a user. Anyone serious about Docker images (in production) should be using shas, and that removes a lot of the need for saying "yesteryear's version". And as a user, I think more about what Python version I'm working with than the package manager version I'm using (which is never until it breaks). I do think there is value in pre-release/LTS/nightly style tags, but that's a much smaller set than "every poetry version". Also: following the upstream pattern is awesome for discovery and migration. Having an "extension" image shoot of in an orthogonal direction makes switching harder...
compared to
For similar reasons; I'd argue for publishing from inside the the Poetry organization on GitHub to a Poetry organization on Docker Hub. It's easily discoverable; while still part of the Poetry maintainer's team ownership -- clear connection to community/maintainers and their needs/dev cycle. That also makes it easy to change publishing later; to anywhere, or even setup multiple publishing destinations -- or moving it into the Docker org if that makes sense later. So it's less committal while working out how this should work and what makes sense for Poetry. |
|
I submitted a draft PR with my code: #5491 The next step is CI/CD, so we need to decide where to push docker images. |
For now, would it be possible to have a "tutorial" section in the docs to show best practices such as disabling dependency caching, using |
Hi everyone, I created repository aiming this purpose https://github.com/mateusoliveira43/docker-image-poetry I tried to follow the style of the Python Docker Image repository. The Image is already in Docker Hub https://hub.docker.com/r/mateusoliveira43/poetry (if you want a specific version of Poetry/Python that is not there yet, just open a issue there, and we can add it 😄) I would be happy to help to create an official Poetry Image 😃 |
I did a scan with the latest grype and it came back with zero fixable vulns ✨
|
I feel like creating a base image with poetry installed will lead to a lot of discussions about what base image(s) to use, and create a horrible jam where anyone using their own or an unsupported base image will suffer, and the network of builds to support a mass variety of different images will lead to a level of complexity that the poetry team really shouldn't have to deal with. What about, as an alternative, releasing an OCI devcontainer feature that allows addition of poetry to whatever base image we want (more info in this blog post)? It's a pain point for me having to rewrite all my dockerfiles every time there's a bit of a shift here so I could probably justify allocating a day or two of my team's time to achieving this, but would want to see some buyin from the community and maintainers here first. Whdjathink, folks? |
@thclark we already have a PR for Dev Containers implementation |
Perfect, thanks @Secrus. I'd assumed that would straightforwardly solve the issue but now am not sure whether it's even possible to reuse those features in a production build. If it's possible, surely that'd solve our problem here, so I asked an SO question](https://stackoverflow.com/questions/76365548/is-it-possible-to-install-devcontainer-features-in-production-container-builds) |
@thclark I took a look at your repo and I have a suggestion for you, because I've also built my own poetry image: you can use Docker args to reduce everything to a single Dockerfile. ARG PYTHON_DOCKER_IMAGE
ARG POETRY_VERSION
# Use build layer
FROM python:${PYTHON_DOCKER_IMAGE} as builder
ARG PYTHON_DOCKER_IMAGE
ARG POETRY_VERSION
ENV POETRY_HOME=/opt/poetry
RUN echo PYTHON_DOCKER_IMAGE=${PYTHON_DOCKER_IMAGE} POETRY_VERSION=${POETRY_VERSION}
RUN if [ -z "${PYTHON_DOCKER_IMAGE##*alpine*}" ]; then \
echo "Installing required packages for alpine image"; \
apk update; \
apk add gcc musl-dev python3-dev libffi-dev openssl-dev cargo; \
else \
echo "Skipping installation of required packages for alpine image"; \
fi
# Install poetry
ADD get-poetry.py /opt/get-poetry.py
RUN pip3 install --no-cache-dir --upgrade pip
RUN python /opt/get-poetry.py --version ${POETRY_VERSION}
# Use runtime layer
FROM python:${PYTHON_DOCKER_IMAGE}
# Disable creation of virtual environments to reduce image size
ENV POETRY_VIRTUALENVS_CREATE=false \
POETRY_HOME=/opt/poetry \
PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONHASHSEED=random \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on
# Copy poetry into image
COPY --from=builder /opt/poetry /opt/poetry
ENV PATH="${POETRY_HOME}/bin:${PATH}"
RUN pip3 install --no-cache-dir --upgrade pip
CMD ["python3"] I have the And then you can do export POETRY_VERSION=1.7.1
export PYTHON_VERSION=3.12
export PYTHON_DOCKER_IMAGE_TYPE=alpine
export IMAGE_NAME=poetry-${POETRY_VERSION}-${PYTHON_VERSION}
docker build \
--build-arg PYTHON_DOCKER_IMAGE=${PYTHON_VERSION}${PYTHON_DOCKER_IMAGE_TYPE:+-$PYTHON_DOCKER_IMAGE_TYPE} \
--build-arg POETRY_VERSION=${POETRY_VERSION} \
-f Dockerfile \
-t ${IMAGE_NAME} \
. I have slightly adjusted the commands here, so no guarantee it works out of the box. You can very nicely use this in CI/CD to deploy multiple Docker images for every Python version you desire if there is a new poetry release. I takes me less than a minute to roll out a new set of Docker images if there is a release. |
That's very nice, thanks @faemmi |
Feature Request
I'm curious if official docker containers could be created (automated via Github actions).
Of course it's easy to install Poetry in a Dockerfile using
get-poetry.py
, but I see two issues:get-poetry.py
installs the latest version of Poetry and doesn't appear to have a flag for selecting the version. It's good practice for Docker containers have reproducible builds, and this instability in Poetry version prevents that. An official container could pin the Poetry version and allow for reproducible builds.For context I'd like to use Poetry in a Docker container to export the
requirments.txt
, since it's error-prone and troublesome to manually keep that export up to date and it's redundant information when we havepyproject.toml
andpoetry.lock
.I'm actually surprised there are not already official Poetry Docker containers, so I'm wondering if this might be an intentional decision. On the other hand if this sound like a good idea, I can volunteer to work on a PR for it.
The text was updated successfully, but these errors were encountered: