Search code examples
pythonpython-3.xdockerpipenv

Building pipenv with requirements file on Docker


I am having a big trouble building my dockerised version of flask app. At first I am not able to install any dependencies from requirements.txt file which is provided inside the container itself. Here is a folder structure:

.
├── app
│   ├── ASRModule.py
│   ├── auth.py
│   ├── config
│   ├── files
│   ├── index.py
│   ├── __init__.py
│   ├── Interval.py
│   ├── MySQLDBHandler.py
│   ├── __pycache__
│   ├── SIPCall.py
│   ├── SOAPClient.py
│   ├── static
│   ├── stats.py
│   ├── templates
│   ├── TrunkOccupation.py
│   └── TrunkTraffic.py
├── Dockerfile
├── instance
└── requirements.txt

And my Dockerfile on which I want to build a containter:

FROM python:3.5.2-alpine

COPY . /flask
WORKDIR /flask

RUN pip install --upgrade pip
RUN pip install pipenv

CMD ["pipenv", "shell", "testshell"]
CMD ["pipenv","install", "-r ./requirements.txt"]

To my understanding, after completed build I should have same folder structure except one above directory called flask which will hold all aforementioned files and dirs. I also should have a virtualenv called testshell to which all dependencies from requirements.txt should be installed. And up until now everything works silky-smooth-fine. To my disappointment, though, after I try to run this container I see a correctly build virtual-env and such error:

Requirements file doesn't appear to exist. Please ensure the file exists in your project directory or you provided the correct path.

I tried various paths for the requirements file but nothing helped. I would appreciate any help which will point me, where I am making mistake.


Solution

  • The error is rather simple, but made hard to notice by the bad error message - it does not say which file it is trying to load. The file it tries to load is '/flask/ ./requirements.txt', i.e. requirements.txt in a subdirectory named space. - c.f. with the error message from pip:

    % "pip" "install" "-r ./requirements.txt"
    Could not open requirements file: 
    [Errno 2] No such file or directory: ' ./requirements.txt'
    

    The fix is to either remove the space, or correctly split the arguments:

    CMD ["pipenv", "install", "-r./requirements.txt"]
    

    or

    CMD ["pipenv", "install", "-r", "./requirements.txt"]
    

    both ought to work.


    I suggest that you will complain about the bad error message to the pipenv issue tracker.