Search code examples
dockerdockerfilepipenvrequirements.txtpipenv-install

Error with pipenv in Dockerfile: No such option: --requirements Did you mean --quiet?


I am trying to build a docker image to run an application, the Dockerfile is as follows:

#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 . .

However, I get the following error:

=> 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

I have tried to change the line 23 of the Dockerfile by different commands but it does not work, what is the correct way? Note: I Cut a part of the Dockerfile to avoid lengthening the code, line 23 that is generating problems is:

RUN pipenv lock -r --dev > requirements.txt

Solution

  • The problem with -r is described in this answer. -r is deprecated and you should use requirements in exchange like follows:

    pipenv requirements --dev > dev-requirements.txt