Python Forum

Full Version: Docker -building a python image
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This is my Dockerfile
FROM python:3.10

#create a working directory
WORKDIR /app

#gets our requirements.txt file into our image
COPY requirements.txt requirements.txt

# Install  packages specified in requirements.txt
RUN pip install -r requirements.txt

#adds our source code into the image
COPY . .

CMD [ "python", "manage.py" , "runserver" ,"0.0.0.8000"]
when i am running above code in windows powershell with the command
docker build -t "test" . 
,I am getting the error as in attachment. The error occurs while executing pip install requirement.txt file
how do i go about handling the error
Looks like a network problem. Are you able to run pip successfully on the host?
(Jul-13-2022, 06:19 AM)ndc85430 Wrote: [ -> ]Looks like a network problem. Are you able to run pip successfully on the host?

yes,i was network problem.Could fix it with help of proxy.
Right now i am able to run the docker build command and install all libraries.But the image is not created successfully and i got following error

#10 6.617   Downloading pysftp-0.2.9.tar.gz (25 kB)
#10 6.637   Preparing metadata (setup.py): started
#10 6.931   Preparing metadata (setup.py): finished with status 'done'
#10 7.114 Collecting pytz==2022.1
#10 7.158   Downloading pytz-2022.1-py2.py3-none-any.whl (503 kB)
#10 7.220      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 503.5/503.5 kB 8.7 MB/s eta 0:00:00
#10 7.301 Collecting six==1.16.0
#10 7.343   Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
#10 7.423 Collecting sqlparse==0.4.2



#10 7.468   Downloading sqlparse-0.4.2-py3-none-any.whl (42 kB)
#10 7.490      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 42.3/42.3 kB 2.1 MB/s eta 0:00:00
#10 7.616 Collecting backports.zoneinfo
#10 7.663   Downloading backports.zoneinfo-0.2.1.tar.gz (74 kB)
#10 7.678      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 74.1/74.1 kB 6.8 MB/s eta 0:00:00
#10 7.899   Installing build dependencies: started
#10 70.13   Installing build dependencies: still running...
#10 130.7   Installing build dependencies: still running...
#10 191.8   Installing build dependencies: still running...
#10 253.8   Installing build dependencies: still running...
#10 317.9   Installing build dependencies: still running...
#10 378.0   Installing build dependencies: still running...
#10 378.1   Installing build dependencies: finished with status 'error'
#10 378.1   error: subprocess-exited-with-error
#10 378.1
#10 378.1   × pip subprocess to install build dependencies did not run successfully.
#10 378.1   │ exit code: 1
#10 378.1   ╰─> [7 lines of output]
#10 378.1       WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f8fb26529a0>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/setuptools/
#10 378.1       WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f8fb2652c70>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/setuptools/
#10 378.1       WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f8fb2652d90>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/setuptools/
#10 378.1       WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f8fb2652f70>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/setuptools/
#10 378.1       WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f8fb25c3190>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/setuptools/
#10 378.1       ERROR: Could not find a version that satisfies the requirement setuptools>=40.8.0 (from versions: none)
#10 378.1       ERROR: No matching distribution found for setuptools>=40.8.0
#10 378.1       [end of output]
#10 378.1
#10 378.1   note: This error originates from a subprocess, and is likely not a problem with pip.
#10 378.1 error: subprocess-exited-with-error
#10 378.1
#10 378.1 × pip subprocess to install build dependencies did not run successfully.
#10 378.1 │ exit code: 1
#10 378.1 ╰─> See above for output.
#10 378.1
#10 378.1 note: This error originates from a subprocess, and is likely not a problem with pip.
------
executor failed running [/bin/sh -c pip  install -r requirements.txt]: exit code: 1
My requirements.txt contains :

asgiref==3.5.2
bcrypt==3.2.2
cffi==1.15.0
crontab==0.23.0
cryptography==37.0.2
Django==4.0.5
django-cors-headers==3.13.0
django-cron==0.6.0
django-crontab==0.7.1
django-extensions==3.1.5
djangorestframework==3.13.1
paramiko==2.11.0
pycparser==2.21
PyNaCl==1.5.0
pysftp==0.2.9
pytz==2022.1
six==1.16.0
sqlparse==0.4.2
tzdata==2022.1
whitenoise==6.2.0
and My docker file looks like this

# The first instruction is what image we want to base our container on
# We Use an official Python runtime as a parent image
FROM python:alpine3.10

#create a working directory
WORKDIR /app

#gets our requirements.txt file into our image
COPY requirements.txt requirements.txt

# Install packages specified in requirements.txt
RUN pip install --upgrade pip
RUN pip install --upgrade setuptools
RUN pip install -r requirements.txt

#adds our source code into the image
COPY . .

CMD [ "python", "manage.py" , "runserver" ,"0.0.0.8000"]



I even tried to install setuptools by specifying in requirements.txt.But still the errror persists.
It doesn't look like a problem with setuptools itself - the connection is timing out. Do you have more network issues? Is there a firewall or something that isn't letting you access PyPI over HTTPS?
(Jul-13-2022, 12:10 PM)ndc85430 Wrote: [ -> ]It doesn't look like a problem with setuptools itself - the connection is timing out. Do you have more network issues? Is there a firewall or something that isn't letting you access PyPI over HTTPS?


Yes,there is a firewall and i modified the statements as below in dockerfile .I am able to install all dependencies,but image not created because of above error

RUN pip --proxy http://10.1XX.XXX.XX:80XX install --upgrade pip
RUN pip --proxy http://10.1XX.XXX.XX:80XX install --upgrade setuptools>=40.8.0
RUN pip --proxy http://10.1XX.XXX.XX:80XX install -r requirements.txt
I tried 2 ways,
1)I added a setuptools even in requirements.txt
2)added pip --proxy http://10.1XX.XXX.XX:80XX install --upgrade setuptools>=40.8.0 in docker file
Both ways still give the same error as i posted before.But I could install all dependencies mentioned in requirements.txt.After installing all libraries,the before mentioned error pops up