0

I have a requirements.txt (which I got from pipreqs) that looks like this:

fastapi==0.95.2
numpy==1.24.3
pandas==2.0.1
pandas_datareader==0.10.0
pandas_market_calendars==4.1.4
protobuf==4.23.1
pydantic==1.10.7
scikit_learn==1.2.2
scipy==1.10.1
SQLAlchemy==2.0.14
toml==0.10.2
tornado==6.2
uvicorn==0.22.0
xmlrpclib==1.0.1
yfinance==0.2.18

The container file looks like this:

FROM python:3.10.9
WORKDIR /app
COPY . /app
RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 3000
CMD ["uvicorn", "myapp_endpoints:app", "--host", "0.0.0.0", "--port", "3000"]

When I try to build the dockerfile:

(base) idf@R430:~/Documents/python/$ sudo docker build -t my-fastapi-app .
[+] Building 12.0s (8/8) FINISHED                                                                                                                                                                                                                                                                                                                    
 => [internal] load .dockerignore                                                                                                                                                                                                                                                                                                               0.1s
 => => transferring context: 2B                                                                                                                                                                                                                                                                                                                 0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                                                                                                                                                                            0.1s
 => => transferring dockerfile: 226B                                                                                                                                                                                                                                                                                                            0.0s
 => [internal] load metadata for docker.io/library/python:3.10.9                                                                                                                                                                                                                                                                                0.4s
 => [1/4] FROM docker.io/library/python:3.10.9@sha256:826b7a08361e632d25f89a96a9906e3e6e28818e9a68aa1cdc05e9cd4f6e5026                                                                                                                                                                                                                          0.0s
 => [internal] load build context                                                                                                                                                                                                                                                                                                               0.1s
 => => transferring context: 138.75kB                                                                                                                                                                                                                                                                                                           0.1s
 => CACHED [2/4] WORKDIR /app                                                                                                                                                                                                                                                                                                                   0.0s
 => CACHED [3/4] COPY . /app                                                                                                                                                                                                                                                                                                       `0.0s`

I get an error:

 => ERROR [4/4] RUN pip install --no-cache-dir -r requirements.txt                                                                                                                                                                                                                                                                             11.4s
------                                                                                                                                                                                                                                                                                                                                               
 > [4/4] RUN pip install --no-cache-dir -r requirements.txt:                                                                                                                                                                                                                                                                                         
#0 3.433 WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f32ba1ff370>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/fastapi/               
#0 3.934 WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f32ba1ff040>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/fastapi/               
#0 4.937 WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f32ba1fcca0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/fastapi/               
#0 6.940 WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f32ba1fe1d0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/fastapi/               
#0 10.94 WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f32ba1fe380>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/fastapi/
#0 10.96 ERROR: Could not find a version that satisfies the requirement fastapi==0.95.2 (from versions: none)
#0 10.96 ERROR: No matching distribution found for fastapi==0.95.2
#0 10.97 WARNING: There was an error checking the latest version of pip.
------
Dockerfile:4
--------------------
   2 |     WORKDIR /app
   3 |     COPY . /app
   4 | >>> RUN pip install --no-cache-dir -r requirements.txt
   5 |     EXPOSE 3000
   6 |     CMD ["uvicorn", "myapp_endpoints:app", "--host", "0.0.0.0", "--port", "3000"]
--------------------

It doesn't matter how many lines I remove from the requirements.txt file. The next line gives a similar error.

If I restart the docker service, same problem:

sudo service docker restart

if I run it works fine

pip install -r requirements.txt

My internet connection is fine:

PING www.yahoo.com(media-router-fp74.prod.media.vip.bf1.yahoo.com (2001:4998:124:1507::f001)) 56 data bytes
64 bytes from media-router-fp74.prod.media.vip.bf1.yahoo.com (2001:4998:124:1507::f001): icmp_seq=1 ttl=50 time=49.1 ms
64 bytes from media-router-fp74.prod.media.vip.bf1.yahoo.com (2001:4998:124:1507::f001): icmp_seq=2 ttl=50 time=43.1 ms
64 bytes from media-router-fp74.prod.media.vip.bf1.yahoo.com (2001:4998:124:1507::f001): icmp_seq=3 ttl=50 time=42.9 ms
64 bytes from media-router-fp74.prod.media.vip.bf1.yahoo.com (2001:4998:124:1507::f001): icmp_seq=4 ttl=50 time=44.7 ms
64 bytes from media-router-fp74.prod.media.vip.bf1.yahoo.com (2001:4998:124:1507::f001): icmp_seq=5 ttl=50 time=42.3 ms

EDIT 1

If I run

docker run hello-world

I get:

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

EDIT 2

I added to the Dockerfile:

RUN curl -I https://www.google.com

I get this error:

ERROR: failed to solve: process "/bin/sh -c curl -I https://www.google.com" did not complete successfully: exit code: 6

EDIT 3

Bizarre, I tried this on another Ubuntu computer and it works. I am now confused but at least I got something

EDIT 4

The two machines are running different versions of Ubuntu:

Works:

lsb_release -a

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.2 LTS
Release:    22.04
Codename:   jammy

uname -a
Linux vw-esxi-vm 5.19.0-38-generic #39~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 17 21:16:15 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Fails:

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.2 LTS
Release:    20.04
Codename:   focal

uname -a
Linux R430 5.15.0-71-generic #78~20.04.1-Ubuntu SMP Wed Apr 19 11:26:48 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

EDIT 5

I got it to work by uninstalling docker completely by following ChatGPT instructions to delete it, then followed the ChatGPT instructions to install it. LOL!

Ivan
  • 7,448
  • 14
  • 69
  • 134
  • Please [edit] the post and share the containerfile used. Sharing the directory structure of the project might also be necessary. – Turing85 May 19 '23 at 18:06
  • Hmm... an answer to [this question (`stackoverflow.com`)](https://stackoverflow.com/questions/44761246/temporary-failure-in-name-resolution-errno-3-with-docker) suggests to `sudo service docker restart`. Other answers suggest adding a specific DNS server. I'd give those answers a shot. – Turing85 May 19 '23 at 18:12
  • @Turing85 restart doesn't help – Ivan May 19 '23 at 18:22
  • That's a networking issue, the environment used to build the docker image is having DNS (or internet) issues, try adding `RUN ping google.com` to see if it gets resolved. – Husseinfo May 19 '23 at 20:44
  • Just to make sure, my internet connection is fine. See the OP for proof. – Ivan May 19 '23 at 21:09
  • @Ivan - the host internet connection is fine, but the pip install is running within the docker container. try to build and load a similar container without the "pip install" and run ping from within the container. use a hostname in your ping because the problem is a resolving problem and not a networking one. – Gal Weiss May 19 '23 at 21:21
  • @GalWeiss see Edit 2. I am not sure if this means it can't find curl, or the DNS can't be resolved – Ivan May 19 '23 at 21:55
  • See Edit 3. I got it to work on another computer – Ivan May 19 '23 at 22:18
  • @Ivan - I'm happy to read you solved it, this is most likely something odd about the dns resolving settings of the container itself. – Gal Weiss May 20 '23 at 10:46
  • Please avoid editing question with "I got it to work by..." - if some action resolved your problem, it's an answer. Question with 0 answers are less likely to help anyone, because people don't look up answers in the question body. Please remove that part and post it as self-answer instead. – STerliakov May 21 '23 at 16:14

0 Answers0