我目前有一个 Docker 容器,我想开始在其中使用诗歌。 我已经查看了几个文档和示例,但不确定这是否适合我。 Poetry 及其依赖项已安装在项目中。
之前的dockerfiles是
FROM python:3.9 as base
ENV PYTHONUNBUFFERED 1
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
binutils libproj-dev gdal-bin \
netcat postgresql-client sudo curl \
&& apt-get clean -y \
&& mkdir /code
ADD requirements.txt /code/requirements.txt
RUN pip install -r /code/requirements.txt
FROM base
ADD requirements.txt /code/requirements.txt
RUN pip install -r /code/requirements.txt
COPY . /code
WORKDIR /code
ENTRYPOINT ["./docker-entrypoint.sh"]
我已添加..
FROM python:3.9 as base
ENV PYTHONUNBUFFERED 1
WORKDIR /code
From base as builder
ENV PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
POETRY_VERSION=1.0.0 \
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
binutils libproj-dev gdal-bin \
netcat postgresql-client sudo curl \
&& apt-get clean -y \
&& mkdir /code
ADD requirements.txt /code/requirements.txt
RUN pip install -r /code/requirements.txt
RUN curl -sSL https://install.python-poetry.org | python3 - --version $POETRY_VERSION
RUN python -m venv /venv
COPY poetry.lock pyproject.toml /code/
COPY . /code
FROM base as final
ADD requirements.txt /code/requirements.txt
RUN pip install -r /code/requirements.txt
COPY . /code
WORKDIR /code
ENTRYPOINT ["./docker-entrypoint.sh"]
这是在 docker 容器内实现诗歌的正确方法吗?我该如何测试这个?
诗歌时三个主要的事情很重要,
RUN pip3 install -U pip poetry
RUN poetry config virtualenvs.create false
RUN poetry install --no-interaction --no-ansi
docker build -t tag_name_your_project .
您原来使用
Dockerfile
的工作[我认为]诗歌pipx
出现在下面。使用 curl
的工作诗歌安装在 here。
填写 ${POETRY_VERSION}、${USER}、${UID} 和 ${GID} 的值。
FROM python:3.9 as base
ENV PYTHONUNBUFFERED 1
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
binutils libproj-dev gdal-bin \
netcat postgresql-client sudo curl \
&& apt-get clean -y \
&& mkdir /code
# Install pipx so we can install isolated poetry system wide
RUN python3 -m pip install --no-cache-dir --user pipx && \
python3 -m pipx ensurepath
# Now install poetry to install our dependencies
RUN pipx install poetry==${POETRY_VERSION}
# Copy our poetry configuration files to know what to install
COPY --chown=${UID}:${GID} pyproject.toml "/home/${USER}/work/"
COPY --chown=${UID}:${GID} poetry.lock "/home/${USER}/work/"
# Install our package requirements via poetry. No venv. Squash max-workers error.
RUN poetry config virtualenvs.create false && \
poetry config installer.max-workers 10 && \
poetry install --no-interaction --no-ansi --no-root -vvv && \
poetry cache clear pypi --all -n
COPY . /code
WORKDIR /code
ENTRYPOINT ["./docker-entrypoint.sh"]