Reputation: 179
I currently have a running docker stack, with services able to communicate with each other through a bridge network.
Even if the inbound connection works (Internet --> Containers), the outbound doesn't: I am unable to wget;curl;etc towards internet, from those containers.
My host runs on Centos, and given the amount of posts related to this kind of issues online, I disabled firewalld to check if it was the issue: It wasn't.
CentOS Linux release 7.9.2009
Docker version 1.13.1, build 0be3e21/1.13.1
docker-compose version 1.28.5, build c4eb3a1f
networks:
mynetwork:
driver: bridge
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.19.0.0/16",
"Gateway": "172.19.0.1"
}
]
},
"Internal": false,
"Attachable": true,
"Containers": {
[...]
},
"Options": {},
"Labels": {
"com.docker.compose.network": "mynetwork",
"com.docker.compose.project": "myproject",
"com.docker.compose.version": "1.28.5"
}
Curl with url:
curl www.tester.com
curl: (6) Could not resolve host: www.tester.com
Curl with IP work though.
It seems to be related to the DNS, but I lack knowledge in this field. How can I tweak my configuration to grant access to internet to my containers ? (Without setting network: host)
EDIT:
Setting the DNS into the docker-compose file worked like a charm. Thanks @atline for the lead !
dns:
- 8.8.8.8
dns_search:
- domain.name
For those who have a similar issue despite setting the DNS into docker setting files (daemon / docker.service / ...), it looks like docker-compose doesn't use Docker "custom" default values; So use the docker-compose directly
Upvotes: 1
Views: 1694
Reputation: 31684
There are several ways for you to configure dns for container:
1. Add dns when run container:
docker run --dns 192.168.1.1 busybox nslookup google.com
2. Configure /etc/docker/daemon.json
to set default dns for all containers:
{
"dns": ["192.168.1.1", "8.8.8.8"]
}
Then, sudo service docker restart
to make it effect.
3. Change systemd script /lib/systemd/system/docker.service
to include the --dns
:
[Service]
ExecStart=/usr/bin/dockerd --dns 192.168.1.1 -H fd:// -H tcp://0.0.0.0:2375 --containerd=/run/containerd/containerd.sock
Then restart the docker to make it effect:
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo systemctl status docker
NOTE: You should use your real dns to replace the value of 192.168.1.1.
Upvotes: 2