Container DNS: how web finds api by name
Select an icon to see what it is.
Step 6 of 6
The default bridge has no name lookup
Containers on the default docker0 bridge get a copy of the host's resolv.conf, not 127.0.0.11. So they cannot resolve each other by name, only by IP. This is why you create a user-defined network like shop-net.
$ docker run --rm alpine cat /etc/resolv.conf PrevNext
/etc/resolv.conf on the default bridge
nameserver <the host's DNS server>(no embedded DNS, no container names)
Try it yourself
Look up a container by name on a user-defined network, then on the default bridge.
$ docker network create --subnet 172.18.0.0/16 shop-net$ docker run -d --name api --network shop-net nginx$ docker run --rm --network shop-net alpine nslookup api$ docker run -d --name old nginx$ docker run --rm alpine nslookup old$ docker rm -f api$ docker rm -f old$ docker network rm shop-net