My Docker Container Has No Internet — How to Fix It

When running Docker containers, you might notice they can’t access the internet — for example:

ping google.com
# ping: bad address 'google.com'

or when installing packages inside a container:

apt-get update
# Temporary failure resolving 'deb.debian.org'

This issue is fairly common and can be frustrating, but the good news is it’s usually a networking configuration problem.


1️⃣ Common Causes of “No Internet” in Docker Containers

🔹 1. Docker Daemon Network Issues

Docker uses its own virtual bridge network (docker0) to provide connectivity. If this network is misconfigured, containers won’t reach the internet.

🔹 2. DNS Resolution Problems

Containers rely on DNS to resolve domain names. If the host system’s DNS is not passed correctly, you’ll see errors like Temporary failure resolving.

🔹 3. Firewall or iptables Rules

Overly strict firewall rules can block container traffic to the outside world.

🔹 4. Corporate Proxy / Restricted Network

If you’re behind a proxy, containers may not know how to route traffic through it.


2️⃣ How to Fix No Internet in Docker Containers

✅ Step 1: Test Basic Networking

Run an Alpine test container:

docker run --rm alpine ping -c 3 8.8.8.8
  • If this works, but DNS names don’t resolve → it’s a DNS problem.
  • If this fails, it’s a network/bridge issue.

✅ Step 2: Restart Docker

Sometimes, simply restarting Docker fixes broken networking:

On Linux:

sudo systemctl restart docker

On macOS / Windows (Docker Desktop):

  • Restart Docker Desktop from the UI.

✅ Step 3: Fix DNS in Docker

Manually set DNS servers when running a container:

docker run --rm --dns=8.8.8.8 alpine ping -c 3 google.com

Or configure it globally in /etc/docker/daemon.json:

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

Then restart Docker.


✅ Step 4: Check Network Settings

List networks:

docker network ls

Inspect the default bridge:

docker network inspect bridge

If it looks corrupted, recreate it:

docker network rm bridge
docker network create bridge

✅ Step 5: Handle Proxy Settings

If you’re behind a corporate proxy, pass proxy environment variables:

docker run -e http_proxy=http://proxy.company.com:8080 \
           -e https_proxy=http://proxy.company.com:8080 \
           alpine curl http://example.com

For system-wide configuration, set them in Docker’s systemd service file or Docker Desktop settings.


✅ Step 6: Firewall / iptables Rules

On Linux, Docker modifies iptables rules. If your firewall overrides them, outbound connections may fail.

Check iptables NAT rules:

sudo iptables -t nat -L -n

Make sure MASQUERADE rules exist for Docker traffic.


📌 Summary

If your Docker container has no internet:

  1. Test with ping 8.8.8.8 → rules out DNS issues.
  2. Restart Docker to reset networking.
  3. Fix DNS (/etc/docker/daemon.json"dns": ["8.8.8.8"]).
  4. Check/recreate Docker bridge network.
  5. Configure proxy settings if needed.
  6. Review firewall/iptables rules.

With these steps, you’ll restore internet connectivity inside your Docker containers.

Sharing Is Caring:

Leave a Comment