1

I cannot execute any command requiring internet connection inside any Docker container.

Works:

docker run ubuntu /bin/echo 'Hello world'

Does not work:

docker run ubuntu apt-get update

Err:1 http://archive.ubuntu.com/ubuntu xenial InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Err:2 http://archive.ubuntu.com/ubuntu xenial-updates InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Err:3 http://archive.ubuntu.com/ubuntu xenial-security InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Reading package lists...
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial-updates/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial-security/InRelease  Temporary failure resolving 'archive.ubuntu.com'

Similar with pip and ping.

I am on Ubuntu 16.04 and not using firewall or corporate proxy server and have tried to restart Docker. Not using docker-machine or boot2docker.

Sashko Lykhenko
  • 1,554
  • 4
  • 20
  • 36

3 Answers3

6

Got answer on SuperUser:

pkill docker
iptables -t nat -F
ifconfig docker0 down
brctl delbr docker0
docker -d

"It will force docker to recreate the bridge and reinit all the network rules"

Community
  • 1
  • 1
Sashko Lykhenko
  • 1,554
  • 4
  • 20
  • 36
0

In my case only deleteting the docker0 interface wasn't enough,j I had to delete the br interfaces (see ip link) as well.

For the Linux users out there that use systemd:

#!/usr/bin/env sh
if ! [ "$(id -u)" = "0" ]; then
   echo "Run as root please."
   exit 1
fi

# not sure if this is needed
iptables -t nat -F

# stop docker
systemctl stop docker

# stop the `br-...` interfaces.
ip link | awk -F': ' '/: br-/ {print $2}' | xargs -I % ifconfig % down
# ... and remove them
ip link | awk -F': ' '/: br-/ {print $2}' | xargs brctl delbr

# stop the docker0 interface
ifconfig docker0 down
# ... and remove it
brctl delbr docker0

# start docker again, this will re-create the docker0 interface.
systemctl start docker
Akudo
  • 165
  • 1
  • 11
0

I solved it with the following sequence:

  1. Install connman if not installed earlier:
sudo apt update
sudo apt install connman -y
  1. Follow this solution
sudo nano /etc/connman/main.conf
  1. Reboot:
sudo reboot