Hello Docker community,
I am facing an issue where my Docker containers are unable to access the internet due to DNS resolution failures. I am running Docker on Ubuntu 22.04.5 LTS with Docker version 27.5.1-1. This is a newly setup server with fresh Ubuntu 22.04 LTS installation, nevertheless, the other servers with similar configs work perfectly fine. And i could not make it work.
Setup:
- Host system: Ubuntu 22.04.5 LTS
- Docker Version: 27.5.1-1
- Storage Driver: Overlay2
- Cgroup Driver: systemd
- Kernel: 5.15.0-133-generic
- CPU: 4 cores
- Memory: 15.52GiB
- Docker info:
Client:
Version: 27.5.1-1
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: 0.21.1-1
Path: /usr/libexec/docker/cli-plugins/docker-buildx
Server:
Containers: 1
Running: 1
Paused: 0
Stopped: 0
Images: 4
Server Version: 27.5.1-1
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: systemd
Cgroup Version: 2
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
Swarm: inactive
Runtimes: runc io.containerd.runc.v2
Default Runtime: runc
Init Binary: docker-init
containerd version: 753481ec61c7c8955a23d6ff7bc8e4daed455734
runc version: bc20cb4497af9af01bea4a8044f1678ffca2745c
init version: de40ad0
Security Options:
apparmor
seccomp
Profile: builtin
cgroupns
Kernel Version: 5.15.0-133-generic
Operating System: Ubuntu 22.04.5 LTS
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 15.52GiB
Name: icon2-edge
ID: 3a9f4df5-70a8-4cd0-8185-2fefb96493b6
Docker Root Dir: /var/lib/docker
Debug Mode: false
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Problem:
- When trying to access the internet from inside the Docker container, I get DNS resolution failures.Example command:
docker run --rm busybox ping -c 4 google.com
Error:
ping: bad address google.com
also with changing daemon.json in host system i often get:
;; connection timed out; no servers could be reached
Attempts to resolve:
- DNS settings in Docker: I have tried setting DNS directly in Docker commands and container configuration, but the issue persists. Here’s what I attempted:
- Adding DNS servers with
--dns
flag in thedocker run
command. - Modifying
/etc/docker/daemon.json
to use public DNS (e.g., 8.8.8.8, 1.1.1.1) in the host.
- Network configuration:
- I tried creating custom networks with specific DNS configurations using
docker network create
. - Tried switching to
host
network mode in the container using--network host
, but this did not resolve the issue.
- iptables: I checked that
iptables
is configured properly. I also switched betweeniptables
andnftables
backends, using the command:
sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
Nothing seems to work, despite my host system could ping google.com
etc. without any problem. Its the containers that is having the problem.
Any help would be appreciated, do let me know if i could provide any more information.
This problem is very much similar to an older post Docker Containers Unable to Access Internet (DNS Resolution Fails)
but that also got closed without a resolution.