How docker0 is related to eth0?

Please help me understand what is the relation between docker0 and host eth0 ?

Both of them has a zero at the end :slight_smile: You can create user-defined docker network bridges, but docker0 is the default. eth0 is the old name of the first network interface on Linux systems, but many distribution changed that default and use a name that can give you some information about the hardware. docker0 is just docker0 everywhere.

@technerd4u I just googled your thread title just for fun and the first hit was this stackoverfow question: networking - What is the relation between docker0 and eth0? - Stack Overflow. I am surprised you didn’t find it in your own google searches.

Is it correct to say that docker0 acts as another interface similar to eth0 for the docker host?

Can we connect to docker host via docker0 interface IP?

docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        inet6 fe80::42:dfff:fe2b:3359  prefixlen 64  scopeid 0x20<link>
        ether 02:42:df:2b:33:59  txqueuelen 0  (Ethernet)

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 9001
        inet 172.31.16.41  netmask 255.255.240.0  broadcast 172.31.31.255
        inet6 fe80::465:7cff:feda:bb1e  prefixlen 64  scopeid 0x20<link>
        ether 06:65:7c:da:bb:1e  txqueuelen 1000  (Ethernet)

docker0 is not similar to eth0. As I wrote in my first response, the only common feature in the two is that zero at the end. docker0 is a bridge. Every container using that bridge will have a local ip address. You can’t use that to access to host from outside that machine. You can however use the gateway address (172.17.0.1) from the machine to access a local service only if that service is intentionally listening on that IP or the service is listening on every IP on that machine.

There is something else too. Your quoted interface list shows that the mtu setting on eth0 is 9001 and on docker0 it is 1500. This can be a problem when you want a container to communicate over the LAN network with an other machine. I have never learned the best setting for MTU values but this is mine:

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default

You can see that both MTUs are 1500.

But I think I understand why you think there is a relation between the two networks. You have a similar IP address on both. I have the feeling that you are using a virtual machine or WSL on Windows. As far as I know these IP ranges are usually not used on LAN, because there are other ranges like 192.168.x.x or 10.x.x.x, but WSL gets its IP address from the same IP range as Docker. It can cause problems, because if WSL (or VM or anything you use) can get a new IP address when you reboot, its ip adddress can collide with one of the IP addresses of Docker.

If that IP address on eth0 is static and never changes, then it is safe to use, because Docker will not use an IP address if it sees that it is already used.