skip to Main Content

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


  1. Chosen as BEST ANSWER

    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.


  2. 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.

    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
  4. RUN apt-get update -y
    

    Try to run this command and let me if it works

    Login or Signup to reply.
  5. 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

    RUN apk update
    RUN apk add <lib>
    

    Luckily I was using golang:1.19.7 which has an alpine tag golang:1.19.7-alpine.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search