Docker container loses Internet access after setting Docker to use manually created bridge
I need a bridge network for QEMU/KVM virtual machines. But then, if I just install Docker, virtual machines lose Internet access. The solution I have found was making Docker use that existing bridge by editing /etc/docker/daemon.json
. But then, it seems Docker containers lose Internet access. How can I make Internet access available to Docker containers?
Here is the exact steps of things I did to reproduce the problem in VirtualBox.
- Install Manjaro and update everything.
- Install and start Docker
- Create a Ubuntu container and open its shell
- Verify that its Internet access is working by issuing `apt update’.
- Create a bridge network and add an Ethernet connection to it.
- Delete existing
docker0
andWired connection1
. - Create
/etc/docker/daemon.json
with{"bridge": "bridge0"}
. - Reboot
- Delete existing container and recreate a Ubuntu container
- Open its shell and type
apt update
- The container cannot connect to the Internet.
If anything above is unclear, I have recorded the entire operation without any editing. The screen recording is available at: https://filebin.net/94bjw3b7na8ydkyk
I have downloaded the nicolaka/netshoot container and tried printing some network information of the container. It seems that it has an incorrect IP of 192.168.0.1. That is the IP of the router, so it cannot have that IP, I think. Here are the outputs:
ifconfig -a
eth0 Link encap:Ethernet HWaddr 02:42:C0:A8:00:01
inet addr:192.168.0.1 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:227 errors:0 dropped:0 overruns:0 frame:0
TX packets:13 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:12392 (12.1 KiB) TX bytes:986 (986.0 B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:592 (592.0 B) TX bytes:592 (592.0 B)
ip r
default via 192.168.0.214 dev eth0
192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.1
ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
7: eth0@if8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:c0:a8:00:01 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 192.168.0.1/24 brd 192.168.0.255 scope global eth0
valid_lft forever preferred_lft forever
here is ip addr
of the host computer (the virtual machine on which the Docker container is running)
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: bridge0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 3a:ac:8e:f2:ec:ac brd ff:ff:ff:ff:ff:ff
3: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:68:bd:fa brd ff:ff:ff:ff:ff:ff
altname enp2s0
inet 192.168.0.148/24 brd 192.168.0.255 scope global dynamic noprefixroute ens32
valid_lft 43179sec preferred_lft 43179sec
inet6 fd1b:715e:43ca::33b/128 scope global dynamic noprefixroute
valid_lft 43181sec preferred_lft 43181sec
inet6 fd1b:715e:43ca:0:e14d:c46:1e9d:806a/64 scope global noprefixroute
valid_lft forever preferred_lft forever
inet6 fe80::23b0:d83c:a70d:3800/64 scope link noprefixroute
valid_lft forever preferred_lft forever
here is ip r
of the host computer
default via 192.168.0.1 dev ens32 proto dhcp src 192.168.0.148 metric 100
192.168.0.0/24 dev bridge0 proto kernel scope link src 192.168.0.214
192.168.0.0/24 dev ens32 proto kernel scope link src 192.168.0.148 metric 100