我尝试构建一个docker镜像来运行一个应用程序,Dockerfile如下:
#Pull a image
ARG BASE_IMAGE=python:3.9.0-slim-buster
FROM ${BASE_IMAGE} AS requirements-image
# set working directory
WORKDIR /usr/src/app
# set environment varibles
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install system dependencies
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get -y install netcat gcc cron \
&& apt-get clean
# install python dependencies
RUN pip install --upgrade pip
RUN pip install pipenv pytest
COPY Pipfile* ./
RUN pipenv lock -r --dev > requirements.txt
# add app
FROM ${BASE_IMAGE} AS compile-image
WORKDIR /usr/src/app
COPY --from=requirements-image /usr/src/app/requirements.txt /usr/src/app/requirements.txt
# set environment varibles
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install system dependencies
RUN apt-get update \
...continue
RUN python3 -m venv /home/venv
ENV PATH="/home/venv/bin:$PATH"
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1 \
&& update-alternatives --install /usr/local/bin/pip pip /usr/local/bin/pip3 1
RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt
FROM ${BASE_IMAGE} AS runtime-image
ENV PYTHONUNBUFFERED TRUE
COPY --from=compile-image /home/venv /home/venv
ENV PATH="/home/venv/bin:$PATH"
WORKDIR /usr/src/app
EXPOSE 80
COPY . .
但是,我得到以下错误:
=> ERROR [requirements-image 7/7] RUN pipenv lock --requirements > requirements 3.0s
------
> [requirements-image 7/7] RUN pipenv lock --requirements > requirements.txt:
#0 1.588 Usage: pipenv lock [OPTIONS]
#0 1.588 Try 'pipenv lock -h' for help.
#0 1.588
#0 1.588 Error: No such option: --requirements Did you mean --quiet?
------
Dockerfile:23
--------------------
21 | RUN pip install pipenv pytest
22 | COPY Pipfile* ./
23 | >>> RUN pipenv lock --requirements > requirements.txt
24 |
25 | # add app
--------------------
ERROR: failed to solve: process "/bin/sh -c pipenv lock --requirements > requirements.txt" did not complete successfully: exit code: 2
我尝试通过不同的命令更改Dockerfile的第23行,但它不起作用,正确的方法是什么?注意:我剪切了Dockerfile的一部分以避免加长代码,第23行产生问题:
RUN pipenv lock -r --dev > requirements.txt
1条答案
按热度按时间j8ag8udp1#
-r
的问题在this answer中描述。-r
已被弃用,您应该使用requirements
,如下所示: