Docker answers with container names in a network you create. Here: how to create one and connect containers to it.
docker network create <name> creates a network of your own. Docker's DNS works in it: the /etc/resolv.conf of each of its containers has nameserver 127.0.0.11, and this server knows the names of every container in the network. A name is visible only inside the network: a container from another network will not find it.
A container joins a network when it is created — with the --network option of docker run — or on the fly, with docker network connect: no restart is needed for that. A container can be in several networks.
Teach app to find the database
Make app connect to db by name: sudo docker exec app nc -w 2 db 5432 must print db: ok. The containers are running; there is no need to re-create them.
Goals · 0 of 2
- Let app connect to db by name not done yet
- Link app and db with a Docker network not done yet