Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

pedroroccon's avatar

Docker on Ubuntu 22 cannot connect to any external internet address

Hey! I'm facing a weird problem using Docker on a fresh new installation of Ubuntu 22 Desktop. Everytime that I ran the command docker compose up, it tries to get packages from apk repository (Im using an Alpine based image).

The problem is that the repository is not accessible inside my Docker container. It cannot reach any internet address.

Here is my Dockerfile example

Wen I run docker compose up, it throws me the following error

It cannot reach the https://dl-cdn.alpinelinux.org, but If I try with another external URL, it cannot reach too (I've tried to add a RUN ping google.com).

Anyone knows how do solve this problem?

0 likes
1 reply
LaryAI's avatar
Level 58

The issue you're experiencing is likely related to Docker's network configuration on your Ubuntu 22 system. Here are a few steps you can take to troubleshoot and resolve the problem:

  1. Check Docker Network Configuration: Ensure that Docker's network is set up correctly. You can inspect the Docker network settings using the following command:

    docker network inspect bridge
    

    Look for any anomalies in the configuration, such as incorrect IP ranges or missing DNS settings.

  2. Restart Docker Service: Sometimes, simply restarting the Docker service can resolve network issues:

    sudo systemctl restart docker
    
  3. Check DNS Settings: Docker containers use the host's DNS settings by default. Ensure that your host machine's DNS is configured correctly. You can check your DNS settings in /etc/resolv.conf. If necessary, you can specify a custom DNS server for Docker by editing or creating the /etc/docker/daemon.json file:

    {
      "dns": ["8.8.8.8", "8.8.4.4"]
    }
    

    After making changes, restart the Docker service:

    sudo systemctl restart docker
    
  4. Test Network Connectivity: Run a simple Alpine container to test network connectivity:

    docker run --rm alpine ping -c 4 google.com
    

    If this fails, it indicates a broader network issue with Docker.

  5. Check Firewall Settings: Ensure that your firewall settings are not blocking Docker's network traffic. You can temporarily disable the firewall to test:

    sudo ufw disable
    

    If this resolves the issue, you'll need to adjust your firewall rules to allow Docker traffic.

  6. Update Docker: Ensure that you are using the latest version of Docker. Sometimes, network issues are resolved in newer releases.

  7. Check for Conflicting Software: Ensure that no other software is interfering with Docker's network. VPNs, for example, can sometimes cause issues.

By following these steps, you should be able to diagnose and resolve the network connectivity issue within your Docker containers on Ubuntu 22. If the problem persists, consider checking Docker's GitHub issues page or forums for any known issues specific to your version.

1 like

Please or to participate in this conversation.