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!
5
Answers
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.
First make sure you can
ping
to external services. May be tryping 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 thendocker build
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.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 evenwget http://ports.ubuntu.com
was givingconnection timeout
on Docker.Try to run this command and let me if it works
I had pretty much the same issue on Macbook Pro M1 when running
apt-get update
in docker. I had previously built images using the same Dockerfile and it was working fine.Tried a number of things (machine restart / reinstall Docker / removed antivirus) and the issue still remains (Timing out trying to reach a server).
Not ideal, but my workaround was to switch to an Alpine image and run
Luckily I was using
golang:1.19.7
which has an alpine taggolang:1.19.7-alpine
.