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.

2 Answers 2

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
5
  • 4
    This made it temporarily work but I still couldn't docker build. A sudo systemctl restart docker fixed it tho Jan 24, 2016 at 22:41
  • 6
    This is kind of a dubious 'fix'. It's a workaround at best. Oct 31, 2016 at 23:57
  • I have been googling for a while and --net=host saved me
    – skyuuka
    Feb 6, 2018 at 4:55
  • --net host on Docker for Mac allows the containers access to the internet, but disables host access to the containers. Defining a network in docker-compose worked for me. Mar 26, 2018 at 20:56
  • --net is not a docker build option but --network seems to be a valid alias for it
    – Josh
    Apr 3, 2019 at 22:08
13

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

3
  • 1
    This answer is better because it also fixes docker build.
    – wisbucky
    Aug 11, 2017 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, 2017 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 6, 2018 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.