Quiz Entry - updated: 2026.07.31
How do you connect multiple Docker containers?
Attach containers to a shared Docker network so they can reach each other by container name as a hostname.
* On a shared Docker network, containers reach each other by container name as hostname; the host maps port 80 to the app container. *
# Create a network
$ docker network create web
# Create containers on the network
$ docker create --network web -p 80:80 --name myapp myapp:latest
$ docker create --network web --name mydb mongo:latest
# Start containers
$ docker start myapp
$ docker start mydb
Containers on the same network can communicate using container names as hostnames (e.g., myapp can connect to mydb:27017).
Go deeper:
Docker networking (Docker docs) — how container networks let services discover each other by name.