0

Im struggling with building a python docker image. For some reason it seems to be getting hung up installing the packages with pip.

This is the error I am getting (when running docker image build --progress=plain -t flask-docker .):

#8 [4/5] RUN pip install -r requirements.txt
#8 sha256:39f4de5e15ae40038f02971231a3cc5db01c1c40a9a56fc64b46d23864de055c
#8 1.626 Processing /opt/concourse/worker/volumes/live/976f8942-f51d-4f0e-7352-2a10f0820d0e/volume/cffi_1625814703974/work
#8 1.628 ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: '/opt/concourse/worker/volumes/live/976f8942-f51d-4f0e-7352-2a10f0820d0e/volume/cffi_1625814703974/work'
#8 1.628
#8 1.802 WARNING: You are using pip version 21.2.4; however, version 21.3.1 is available.
#8 1.802 You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
#8 ERROR: executor failed running [/bin/sh -c pip install -r requirements.txt]: exit code: 1

And this is my Dockerfile:

FROM python:3.9-slim-buster
WORKDIR /flask-app
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
ENV FLASK_ENV=development 
CMD ["flask", "run"]

UPDATE: I believe the error is due to using conda and doing pip freeze > requirements.txt to get the required packages from inside a conda environment. However I am not sure in this case how to save the requirements properly with conda and still use pip to install the packages in docker. Also what in the requirements.txt file is causing the issues. Below is the requirements.txt file.

arrow==1.2.1
brotlipy==0.7.0
certifi==2021.5.30
cffi @ file:///opt/concourse/worker/volumes/live/976f8942-f51d-4f0e-7352-2a10f0820d0e/volume/cffi_1625814703974/work
chardet @ file:///opt/concourse/worker/volumes/live/7e1102c4-8702-40f2-63d6-f260ce5f85e4/volume/chardet_1607706831384/work
click==8.0.3
conda-package-handling @ file:///opt/concourse/worker/volumes/live/8fb3e065-760b-4a9d-4cd9-aca7fc8baf53/volume/conda-package-handling_1618262145611/work
cryptography @ file:///opt/concourse/worker/volumes/live/d5dda287-c0b3-4861-7262-fab05baa64dc/volume/cryptography_1616769284011/work
dateparser==1.1.0
Flask==2.0.2
idna @ file:///home/linux1/recipes/ci/idna_1610986105248/work
itsdangerous==2.0.1
Jinja2==3.0.3
MarkupSafe==2.0.1
moment==0.12.1
numpy==1.21.4
pandas==1.3.4
pycosat==0.6.3
pycparser @ file:///tmp/build/80754af9/pycparser_1594388511720/work
pyOpenSSL @ file:///tmp/build/80754af9/pyopenssl_1608057966937/work
PySocks @ file:///opt/concourse/worker/volumes/live/112288ac-9cb0-4e73-768b-13baf4ca6419/volume/pysocks_1605305820043/work
python-dateutil==2.8.2
pytz==2021.3
pytz-deprecation-shim==0.1.0.post0
regex==2021.11.10
requests @ file:///tmp/build/80754af9/requests_1608241421344/work
ruamel-yaml-conda @ file:///opt/concourse/worker/volumes/live/e81cf0fe-611a-498e-6e69-a7320057c1ac/volume/ruamel_yaml_1616016689696/work
six @ file:///tmp/build/80754af9/six_1623709665295/work
times==0.7
tqdm @ file:///tmp/build/80754af9/tqdm_1625563689033/work
tzdata==2021.5
tzlocal==4.1
urllib3 @ file:///tmp/build/80754af9/urllib3_1625084269274/work
Werkzeug==2.0.2
vkan
  • 123
  • 4
  • 1
    Please minimize the example. Which package is failing? You should be able to reduce this to two lines: the `FROM` and a `RUN pip install some_package==N.M` – Erik Cederstrand Dec 07 '21 at 12:24
  • Show your `requirements.txt` – phd Dec 07 '21 at 14:16
  • hi @phd i have added the requirements.txt file to the question, thanks for taking a look. – vkan Dec 09 '21 at 15:22
  • @ErikCederstrand thanks for the other stackoverflow link, this helped to understand the error is coming from using conda to generate the requirements.txt file. However I am not sure how to fix this best if I still want to use conda without changing to using a different virtual environment like venv. – vkan Dec 09 '21 at 15:22
  • 1
    You need to recreate your `requirements.txt`: `pip list --format=freeze > requirements.txt` – phd Dec 09 '21 at 16:25
  • @phd this seemed to help a bit and get rid of the 'OS' error i was seeing before and the requirements.txt file look better. However the docker image still doesn't build and stops running at the same stage. I am seeing this error now ```#8 3.528 ERROR: Could not find a version that satisfies the requirement conda-package-handling==1.7.3 (from versions: none) #8 3.529 ERROR: No matching distribution found for conda-package-handling==1.7.3```, as well as ```executor failed running [/bin/sh -c pip install -r requirements.txt]: exit code: 1``` – vkan Dec 10 '21 at 21:30
  • `conda-package-handling` — there is no such package at PyPI: https://pypi.org/project/conda-package-handling/ . This means you cannot install it with `pip`. Remove it from `requirements.txt` and install it with `conda`. – phd Dec 10 '21 at 21:32
  • I assume I can get rid of the requirement conda-package-handling from the pip file manually but it would be nice if there was some way to get conda to work properly with doing the ```pip list --format=freeze > requirements.txt``` so that i don't have to manually go in and delete stuff each time. – vkan Dec 10 '21 at 21:34
  • Every time I remove some package, I am getting an error from another package not in PyPi so their must be a better way of managing these packages without so much manual editing of the requirements.txt? Which i am guessing will also eventually break something if i remove a package which is actually required for the app/python to work properly too. – vkan Dec 10 '21 at 21:40

0 Answers0