Docker Container Cannot Access Internet: Fix

Step-by-step troubleshooting for Docker containers on Linux and Windows. Isolate DNS, network mode, and firewall issues, then apply the matching fix.

Rao Aadil, India 8 min read

Confirm the symptom: host connectivity vs. container connectivity

A Docker container that cannot reach the internet while the host can is almost always failing at one of three layers: the container's network mode and IP configuration, DNS resolution inside the container, or host-level firewall and routing. The steps here isolate which one on Linux and Windows, then apply the matching fix.

Confirm the host has internet access before touching the container. On a Linux host:

ping -c 4 8.8.8.8
curl -I https://example.com

On a Windows host, run the same tests in PowerShell:

Test-NetConnection 8.8.8.8
Invoke-WebRequest -Uri https://example.com -Method Head

If the host fails these, fix the host's network first. If the host works, run the same checks inside the container. On Linux:

docker exec -it mycontainer ping 8.8.8.8
docker exec -it mycontainer wget -qO- https://example.com

Minimal images may not include ping or curl. Use wget, getent hosts example.com, or install diagnostic tools temporarily. On Windows containers, use PowerShell inside the container:

docker exec -it mycontainer powershell Test-NetConnection 8.8.8.8

Test by IP first, then by hostname. If an IP ping works but a hostname lookup fails, the problem is DNS, not routing. If neither works, the container's network interface, route, or host firewall is likely at fault.

Doing this with brynko devOps Agent

Inspect containers, read logs, check stats, restart services and run Compose stacks, just by describing what you want.

“why does this container keep restarting”

It reads the real state of the server before it says anything, shows you the exact command, and waits for your approval. Windows and Linux, over the SSH access you already have.

Download for WindowsSee what else it does

Check the container's network mode and IP configuration

Inspect how the container is attached to the network first. This command works on both Linux and Windows hosts (in PowerShell or bash):

docker inspect -f '{{.HostConfig.NetworkMode}}' mycontainer

That output tells you the network mode. none means the container has no network stack at all. host shares the host's network namespace and is only available on Linux; Windows containers do not support host mode. bridge is the default Docker bridge. A custom name means the container is attached to a user-defined network.

Check the container's IP address and routing table next. On Linux:

docker exec mycontainer ip addr
docker exec mycontainer ip route

On Windows containers:

docker exec mycontainer ipconfig
docker exec mycontainer route print

Confirm the container has an IP address in the expected Docker subnet and a default route via a gateway. A missing default route often explains why outbound traffic never leaves the container.

List the networks with docker network ls and inspect the relevant one with docker network inspect <network>. The default bridge network (bridge) does not provide Docker's embedded DNS; user-defined networks do. If your container must resolve names of other containers or services, put it on a user-defined network.

Test DNS resolution inside the container

If the container can ping IP addresses but cannot resolve domain names, the DNS configuration is the prime suspect.

Run a DNS query inside the container. On Linux:

docker exec mycontainer nslookup example.com
# If nslookup is missing, use getent:
docker exec mycontainer getent hosts example.com

On Windows containers:

docker exec mycontainer powershell Resolve-DnsName example.com

Check which DNS server the container uses. On Linux:

docker exec mycontainer cat /etc/resolv.conf

If the container is on a user-defined network, this file should show nameserver 127.0.0.11, Docker's embedded DNS. If it shows something else—such as a VPN provider's DNS or a manually edited value—that is likely the problem. On the default bridge, Docker copies the host's /etc/resolv.conf into the container, so the value may be your LAN or ISP DNS server.

On Windows containers, run ipconfig /all inside the container to see the configured DNS servers.

Compare that with the host's DNS resolution. Run nslookup example.com on the host (Linux or Windows). If the host resolves but the container does not, the container DNS configuration or Docker's DNS forwarding is broken.

Common causes include a VPN altering the host DNS settings, a custom /etc/resolv.conf mounted into the container, missing --dns flags, or Docker Desktop's DNS proxy failing to forward from WSL2 or Hyper-V.

Inspect host firewall, routing, and NAT for outbound blocking

If the container has a valid IP and route but still cannot reach the internet, host-level firewall or NAT rules may be blocking outbound traffic.

On Linux, examine Docker's NAT and forwarding rules. Run these as root:

iptables -t nat -L -n -v
iptables -L FORWARD -n -v

Docker's default rules allow outbound traffic from the bridge subnet. If you see a DROP policy or a rule that rejects packets from Docker's subnet, that is the culprit. Also confirm IP forwarding is enabled:

sysctl net.ipv4.ip_forward

This should output net.ipv4.ip_forward = 1. If it is 0, enable it temporarily with sysctl -w net.ipv4.ip_forward=1 and persist it in /etc/sysctl.conf.

On Windows, check IP forwarding and firewall rules. In an elevated PowerShell:

Get-NetIPInterface -AddressFamily IPv4 | Select-Object InterfaceAlias,Forwarding
Get-NetFirewallRule | Where-Object { $_.DisplayName -like '*Docker*' -or $_.DisplayName -like '*vEthernet*' }
Get-NetNat

Docker Desktop uses a virtual switch (DockerNAT or vEthernet) for WSL2 or Hyper-V. Outbound traffic must be allowed through Windows Defender Firewall for that adapter. A VPN with split tunneling disabled can also misroute container traffic because the virtual switch traffic may be pushed into the VPN tunnel and dropped.

Also check whether the environment requires a proxy. If the host uses HTTP_PROXY, HTTPS_PROXY, and NO_PROXY environment variables, the container may need the same values to reach the internet.

Apply the fix for the identified cause

After isolating the failing layer, apply the change that matches.

DNS failure: Add explicit DNS servers to the container. With docker run:

docker run --dns 8.8.8.8 --dns 8.8.4.4 myimage

In a Compose file, use the dns: key:

services:
  web:
    dns:
      - 8.8.8.8
      - 8.8.4.4

For containers on user-defined networks, rely on Docker's embedded DNS rather than manually editing /etc/resolv.conf. If you must override, do it with --dns flags or Compose.

Wrong network mode: If the container is on none, change its network mode to bridge or a user-defined network. In Compose, set network_mode: bridge or attach the service to a custom network, then recreate the container. For Windows containers, ensure the desired network (NAT, transparent, or l2bridge) exists. Create it with docker network create -d nat mynat or the appropriate driver, then attach the container.

Firewall or NAT blocking: On Linux, add an ACCEPT rule for the Docker bridge subnet. First find the subnet with docker network inspect bridge, then run:

iptables -I FORWARD -s 172.17.0.0/16 -j ACCEPT
systemctl restart docker

Adjust the subnet to match your setup. On Windows, allow outbound traffic for the DockerNAT or vEthernet adapter in Windows Defender Firewall, then restart Docker Desktop.

Proxy required: Pass proxy variables to the container:

docker run -e HTTP_PROXY=http://host.docker.internal:3128 -e HTTPS_PROXY=http://host.docker.internal:3128 -e NO_PROXY=localhost,127.0.0.1 myimage

On Linux native Docker, host.docker.internal may not resolve; use the host's IP address or add --add-host=host.docker.internal:host-gateway. For the Docker daemon itself on Linux, create /etc/systemd/system/docker.service.d/http-proxy.conf with:

[Service]
Environment="HTTP_PROXY=http://proxy.example.com:3128"
Environment="HTTPS_PROXY=http://proxy.example.com:3128"
Environment="NO_PROXY=localhost,127.0.0.1"

Then run systemctl daemon-reload && systemctl restart docker. On Docker Desktop for Windows, configure the proxy in Docker Desktop settings instead.

After any change, re-run the connectivity test from the first section to confirm the container can now reach the internet.

Verify connectivity and prevent recurrence

Add a health check that tests external connectivity to catch this early. In a Compose service:

services:
  web:
    healthcheck:
      test: ["CMD", "curl", "-f", "https://example.com"]
      interval: 30s
      timeout: 10s
      retries: 3

For Windows containers, use a PowerShell command inside the health check that returns non-zero on failure, such as Invoke-WebRequest -Uri https://example.com -Method Head.

Keep network configuration in Compose or docker run flags rather than making manual changes inside the container. Prefer user-defined networks over the default bridge; they give automatic DNS and better isolation. Document any host firewall changes and note that restarting Docker may reset some manual iptables rules.

Tools that can inspect container state and run read-only diagnostics inside containers can reduce the number of manual steps. An AI agent for Docker can check a container's network mode, DNS settings, and logs, and run ping, nslookup, or curl inside the container when you ask why it cannot reach the internet. However, host firewall and daemon changes still require your action.

Related reading

Fix Docker Container Internet Access

Get step-by-step help to diagnose and resolve Docker container connectivity issues on Linux and Windows without manually piecing together commands.

An AI teammate that builds, runs, fixes, deploys and operates your software, on your machine and on your servers. It reads the real state of your systems, shows you every command before it runs, and never touches production without your approval.

Works with Docker Docker Compose nginx IIS Tomcat MySQL / MariaDB PostgreSQL Redis Linux servers Windows servers AWS Jenkins Let's Encrypt Node.js Python Java .NET Go PHP
  • Every change asks first, and shows you the exact command or diff before it runs.
  • File edits are snapshotted and reversible. Deleted folders are archived, not removed.
  • Private key material never reaches the model, under any setting.
brynko devOps Agent
Docker

the checkout container keeps restarting

read container state checked health check listed ports

It restarts every 40 seconds, and it is the health check failing rather than the app. The check calls /healthz on port 8080, but the app is listening on 3000, so it never passes and Docker keeps killing it.

fix it

one line in compose restarted watched 5 minutes

Done. I corrected the health check port and restarted the service. It has stayed up since, and the check is passing.

Fixed · container healthy

Free download for Windows. 300 free credits on signup, no card, no subscription.

Questions

Common questions

Why can my container ping IP addresses but not resolve domain names?
This usually means the container's DNS configuration is broken or pointing to an unreachable resolver. On user-defined networks, Docker's embedded DNS at 127.0.0.11 should be in /etc/resolv.conf; if it is missing or overridden, the container cannot resolve names. Check with nslookup or getent, and compare to the host's working DNS.
How do I fix Docker container DNS resolution on Windows?
First inspect the container's DNS servers with `ipconfig /all` and test resolution with `Resolve-DnsName`. If the container uses the default NAT network, Docker Desktop's DNS proxy may be misconfigured or a VPN may be altering host DNS; specify `--dns 8.8.8.8` on `docker run` or the `dns:` key in Compose to bypass it. For persistent issues, check Docker Desktop's network settings and restart Docker Desktop.
Does Docker Desktop use a different network than Linux Docker, and why does that matter for internet access?
Yes. Docker Desktop on Windows and Mac runs Docker inside a lightweight VM (WSL2 or Hyper-V) and uses a virtual switch like DockerNAT or vEthernet. Outbound traffic must pass through that virtual switch and the host firewall, so a firewall rule or VPN on the host can block container internet even if the host itself has connectivity. Linux Docker uses the host kernel's netfilter and routing directly, so the failure modes differ.
Why did my container lose internet after I changed firewall rules or enabled a VPN?
Firewall rules or VPN routing policies can block the Docker bridge subnet or the virtual switch used by Docker Desktop. A VPN often forces all traffic through a tunnel and may drop traffic from container networks; you may need to adjust split tunneling or add an allow rule for Docker's subnet. Reverting the firewall change or disconnecting the VPN usually confirms the cause.
How do I allow outbound traffic from Docker containers through the host firewall?
On Linux, add an ACCEPT rule for the Docker bridge subnet, such as `iptables -I FORWARD -s 172.17.0.0/16 -j ACCEPT`, then restart Docker. On Windows, ensure Windows Defender Firewall allows outbound connections for the DockerNAT or vEthernet adapter and restart Docker Desktop. Always verify the subnet from `docker network inspect` before adding rules.
How can I check if Docker's embedded DNS is working correctly inside a container?
Run `docker exec <container> cat /etc/resolv.conf` on Linux and confirm it contains `nameserver 127.0.0.11` when the container is on a user-defined network. Then test resolution with `docker exec <container> nslookup example.com` or `getent hosts example.com`; if the DNS query times out, the embedded DNS or its forwarding to the host is broken. On Windows containers, use `ipconfig /all` to check DNS servers and `Resolve-DnsName` to test.
What is the difference between the default bridge and a user-defined network for outbound internet access?
Outbound internet access works on both by default, but the default bridge does not provide Docker's embedded DNS; containers use the host's DNS servers copied into /etc/resolv.conf. A user-defined network gives automatic DNS resolution for container names via 127.0.0.11 and better isolation. For most Compose stacks, a user-defined network is the better choice.

Keep reading