When a container starts, Docker attaches it to a network. Which network it joins decides what it can reach and how it gets found.
The three you will see first
- bridge: the default. Containers get private addresses on a virtual bridge. Outside traffic reaches them only through published ports.
- host: the container shares the host's network stack. No port mapping is needed, and no isolation either.
- none: no network at all. Useful for jobs that should not talk to anything.
Publishing a port
A container listens on its own port. To reach it from your machine, map a host port to it:
docker run -d -p 8080:80 --name web nginx # host port 8080 -> container port 80
Finding other containers by name
The default bridge does not give containers DNS names. A user-defined network does. Put both containers on the same one and they find each other by name:
docker network create app-net docker run -d --network app-net --name db postgres:16 docker run -d --network app-net --name api my-api:1.0 # inside api, the host name 'db' resolves to the database container
This is the single most useful networking habit in Docker: create a named network for each app, and connect its containers to it.
Quick checks when something fails
docker psshows whether the container is running and which ports it publishes.docker network inspect app-netlists the containers on that network.docker logs <name>shows what the app says when a connection is refused.
Next step
Want to practise this in a live batch?
We run these labs step by step.