no internet inside docker-compose service
The last time I had a problem like that, I solved it like this:
https://github.com/docker/docker/issues/866#issuecomment-19218300
pkill dockeriptables -t nat -Fifconfig docker0 downbrctl delbr docker0docker -d
It will force docker to recreate the bridge and reinit all the network rules.
As for reasons why this happens, I don't have good answers. But I did recently trace the problem back to journald
. When I restart journald
(for example because I changed its config), DNS resolution inside docker-compose containers consistently/reproducibly breaks. I don't know why exactly, I can only say that this is a reliable way for me to reproduce it on RHEL.
EDIT The docker -d
command might not work for you based on the version of docker you are using but don't worry about it, you can omit that command.
Check /etc/default/docker
to ensure it doesn't have the following line:
DOCKER_OPTS="--iptables=false"
Also check /etc/docker/daemon.json
to ensure it doesn't have the following key:
{"iptables":false}
We added this on one server to get UFW working with docker. We then changed to an external firewall. Spent ages looking for the reason external networking wasn't working because it was removed from our deploy guide. Hope this helps someone else.
Docker containers has the ability to access internet by default. Here is how I solved the problem last week: docker container can only access internet with net host
Or you just let the container in host mode:
version: '2'service: nginx: image: nginx network_mode: host
But as @peedee pointed out on comment, this solution will lost network separation between host and containers.