'Cannot run apt-get update in docker
I am having issues connecting with apt-get from a Docker image. To recreate, I can run
sudo docker run -it ubuntu /bin/bash
and then type:
apt-get update
Without fail, the machine is unable to connect and I get a series of errors that look like this:
Failed to fetch http://ports.ubuntu.com/ubuntu-ports/dists/focal/InRelease Could not connect to ports.ubuntu.com:80 (91.189.88.152), connection timed out
I am running an M1 Macbook Pro and have tried:
- Changing DNS settings
- Other docker base images
- I'm able to successfully download from other sources (eg. pip install)
- Disabling IPv6
- Trying another wi-fi network (I'm not behind any firewalls)
None of this has helped so far, and I have been completely unable to apt-get update or apt-get install to work in a docker container. Would greatly appreciate the help!
Solution 1:[1]
Check if you have Private Relay enabled. Disabling it solved for me, without factoring reset the MacBook Pro.
I had the same issue, where in Safari I could access http://ports.ubuntu.com but in Chrome or even wget http://ports.ubuntu.com was giving connection timeout on Docker.
Solution 2:[2]
Figured out I was able to load these URLs in Safari, but not Chrome – which tracks with an ongoing issue I’ve had with this new computer where some sites weren’t loading in Chrome. Do not know exactly what the issue was – probably some weird DNS thing – but a factory reset of my Mac solved the issue.
Solution 3:[3]
First make sure you can ping to external services. May be try ping google.com.
If its not working, check firewall of you laptop. It may be blocking apt repo.
Alternately you can try two options. First using Dockerfile and then docker build
FROM ubuntu
RUN apt update
RUN apt install vim #or any package you want
Or, run the docker image, and then connect to that image and run.
docker run --name my_ubuntu -d ubuntu
docker exec -it my_ubuntu /bin/bash
And then try to run apt update command.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dharman |
| Solution 2 | jeffstern |
| Solution 3 | Sachith Muhandiram |
