Python Forum
Docker -building a python image
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Docker -building a python image
#1
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

Attached Files

Thumbnail(s)
   
Reply
#2
Looks like a network problem. Are you able to run pip successfully on the host?
Reply
#3
(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.
Reply
#4
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.
Reply
#5
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?
Reply
#6
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Building specific Python version on Raspberry PI 5 (Raspbian) andrewk 2 540 Feb-03-2025, 11:41 AM
Last Post: iterate
  Building a DoublyLinkedList in Python - - append method Drone4four 2 1,144 Jan-08-2024, 01:27 PM
Last Post: Drone4four
  building app in XCODE with python phantom115 2 1,658 Aug-02-2023, 11:56 AM
Last Post: phantom115
Lightbulb shutdown host from docker container cosmin1805 0 1,544 Nov-27-2022, 06:34 PM
Last Post: cosmin1805
  Issue in Starting Django project with Docker Prabakaran141 0 1,262 Sep-26-2022, 12:15 PM
Last Post: Prabakaran141
  Building python (3.9.5) with different libexpat version (2.4.6) raghupcr 0 1,821 Feb-25-2022, 11:29 AM
Last Post: raghupcr
  Upload image to Instagram using python/selenium using image URL failed, need help greenpine 5 7,525 Feb-22-2022, 09:42 PM
Last Post: snippsat
  Docker-compose on Pycharm - Connection refused rstambach 3 4,324 Apr-08-2021, 03:07 AM
Last Post: rstambach
  Cannot bring up anaconda in Docker image ErnestTBass 1 2,480 Aug-15-2020, 04:12 AM
Last Post: ndc85430
  PIL Image / python-resize-image AttributeError sallyjc81 1 6,403 Aug-02-2020, 12:06 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020