27

I'm my wits end with this, I've combed every single google result and nothing helps.

I'm completely unable to get docker containers to access the internet. IP forwarding is enabled (net.ipv4.ip_forward = 1), ufw is turned off, I've tried adding the -dns 8.8.8.8 -dns 8.8.4.4 flags. Every possible solution I've ever found on google fails.

Anyone have any idea how to help?

Attempting to reset everything, as recommend here causes the entire thing to break by telling me that docker -d isn't running even though it is.

Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164
user1072692
  • 687
  • 1
  • 8
  • 19

2 Answers2

32

I was facing the same problem. So, to solve that issue I've started the container using the argument --net=host, it worked perfectly for me.

Here goes the full statement

sudo docker start --net=host -it --name ex_ngninx ubuntu
Philipp Kyeck
  • 18,402
  • 15
  • 86
  • 123
Eriky R. Kashivagui
  • 482
  • 1
  • 4
  • 13
  • 4
    This made it temporarily work but I still couldn't `docker build`. A `sudo systemctl restart docker` fixed it tho – Freedom_Ben Jan 24 '16 at 22:41
  • 6
    This is kind of a dubious 'fix'. It's a workaround at best. – johnharris85 Oct 31 '16 at 23:57
  • I have been googling for a while and `--net=host` saved me – skyuuka Feb 06 '18 at 04:55
  • `--net host` on [Docker for Mac](https://www.docker.com/docker-mac) allows the containers access to the internet, but [disables host access to the containers](https://docs.docker.com/docker-for-mac/networking/#there-is-no-docker0-bridge-on-macos). Defining a [network in docker-compose](https://docs.docker.com/compose/networking/) worked for me. – Steven Ensslen Mar 26 '18 at 20:56
  • `--net` is not a `docker build` option but `--network` seems to be a valid alias for it – Josh Apr 03 '19 at 22:08
13

Resolved. I followed these instructions: commented out dns=dnsmasq line in NetworkManager.conf

Richard
  • 56,349
  • 34
  • 180
  • 251
user1072692
  • 687
  • 1
  • 8
  • 19
  • 1
    This answer is better because it also fixes `docker build`. – wisbucky Aug 11 '17 at 22:31
  • Note that in Ubuntu 16+, the command to restart the network manager is now `sudo systemctl restart network-manager` because it's using `systemd` instead of `upstart`. – wisbucky Aug 11 '17 at 22:36
  • Tried all tricks but it keeps shown '0% [Connecting to 120.0.0.1 (120.0.0.1)] [Connecting to 120.0.0.1 (120.0.0.1)]'. Any idea how to fix this? I have the container running in Ubuntu. – BTR Naidu Nov 06 '18 at 15:43