reddd__1
reddd__1

Reputation: 193

Docker error with pipenv on django app: Warning: --system is intended to be used for pre-existing Pipfile

When I was trying to dockerize my django app, I followed a tutorial telling me to structure my Dockerfile like this

FROM python:3.6

ENV PYTHONUNBUFFERED 1

COPY . /code/
WORKDIR /code/

RUN pip install pipenv
RUN pipenv install --system

EXPOSE 8000 

After I saved that and run docker build .

the system threw me this error

Warning: --system is intended to be used for pre-existing Pipfile 
installation,not installation of specific packages. Aborting.

I think it is complaining about the --system suffix above but the tutorial says it's crucial to have it so that my packages are applied in the entire docker container. I'm new to docker and even pipenv because I took over a previous person's code and isn't sure where their pipfile is or even if they have a pipfile. If you have any insights on how to fix this error thank you in advance.

Upvotes: 15

Views: 15661

Answers (4)

Jose Carlos Coutinho
Jose Carlos Coutinho

Reputation: 116

Be careful when using Docker bind mounts!

Summary: In my case, I was using bind mounts in my dev environment, and mounting a docker bind mount on a non-empty directory would overwrite the contents of the container's directory, removing the Pipfile and Pipfile.lock, which showed the error mentioned when running the container.

Explanation

Directory structure on the host

> ls project/
docker-compose.yml Dockerfile Pipfile Pipfile.lock app/

Dockerfile

My Dockerfile would copy the contents of the project and then install the dependencies with pipenv, like this:

FROM python:3.8
# ...
COPY Pipfile Pipfile.lock /app/
RUN pipenv install --deploy --ignore-pipfile
COPY ./app /app/
CMD ["pipenv", "run", "uvicorn", "etc..", "--reload"]

Pipfile, Pipfile.lock and the code of ./app would all be in the same /app directory inside the container.

docker-compose.yml

I wanted uvicorn to hot-reload, so I mounted the code in /app inside the container's /app directory.

service:
 app:
   #...
   volumes:
   - type: bind
     source: ./app
     target: /app

This meant that when I changed the code in /app, the code in the container's /app directory would also change.

Effects

The side effect of this bind mount is that the content mounted on /app "obscured" the content previously copied in there.

Container's content with the bind mount:

> ls app/
code1.py code2.py

Container's content without the bind mount:

> ls app/
Pipfile Pipfile.lock code1.py code2.py

Solution

Either make sure that you include the Pipfile and Pipfile.lock as well when mounting the bind mount, or make sure that you COPY these 2 files to a directory that won't get overwritten by a bind mount.

Upvotes: 0

Vadim Bulatov
Vadim Bulatov

Reputation: 171

pipenv --rm

This helped me! I was starting the "Django for beginners" and at the very beginning, got this error (accidently deleted Pipfile & Pipfile.lock)

Upvotes: 17

Nick3rman
Nick3rman

Reputation: 1

It has Error in pipenv

It is 👇
ERROR:: --system is intended to be used for pre-existing Pipfile installation, not installation of specific packages. Aborting.

try it

pipenv check or python3 -m pipenv check

Upvotes: 0

Sardorbek Imomaliev
Sardorbek Imomaliev

Reputation: 15400

Your warning is saying you that there is no Pipfile in your project dir.

--system is intended to be used for pre-existing Pipfile.

So before running

docker build .

run

pipenv install 

in your project folder

Upvotes: 6

Related Questions