I am trying to build the simplest of the docker image with poetry.
FROM python:3.9-slim-buster
ARG APP_PATH=/app
ARG PYTHON_VERSION=3.9
ARG POETRY_VERSION=1.1.13
ARG POETRY_HOME="/opt/poetry"
ENV PYTHONDONTWRITEBYTECODE 1 \
PYTHONUNBUFFERED 1 \
POETRY_VERSION=$POETRY_VERSION \
POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_NO_INTERACTION=1\
POETRY_HOME=${POETRY_HOME}
ENV PATH="$POETRY_HOME/bin:$PATH"
RUN apt-get update \
&& apt-get install curl -y \
&& curl -sSL https://install.python-poetry.org | python - --version ${POETRY_VERSION}
WORKDIR $APP_PATH
COPY pyproject.toml poetry.lock $APP_PATH
RUN poetry config virtualenvs.create false \
&& poetry install --no-dev --no-interaction --no-ansi
CMD ["poetry" "-V"]
The docker image builds fine.
But when i try to run it , it fails with
λ docker run test
/bin/sh: 1: [poetry: not found
I am not sure what am i doing wrong here.
But this one works
docker run -it test /opt/poetry/bin/poetry -V
Poetry version 1.1.13
Modified Dockerfile to look like this
ENTRYPOINT [ "poetry" ]
CMD ["-V"]
and viola it works!!!
To have access to poetry
in my Docker build files, I always add the following lines to the beginning of the image build:
FROM --platform=linux/amd64 python:3.9-slim
# use built-in pip to access poetry
RUN pip install poetry
# start installing things with poetry
COPY poetry.lock pyproject.toml .
RUN poetry config virtualenvs.create false
RUN poetry install
Is this not the same for your use case? It seems like the most straight forward way to have access to poetry from within the container in my eyes?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.