Skip to content

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

Quiz

1. What does a container on shop-net use as its DNS server?
2. Where does a lookup for example.com go?
3. Why can't containers on docker0 reach each other by name?