List the Networks
docker network lsA fresh installation has three networks: bridge, host, and none. Compose projects add their own, named after the project. A container you start with docker run and no --network option joins bridge.
The Three Drivers You Meet on One Server
| Network | What the container gets |
|---|---|
bridge | A private address behind NAT |
host | The server's own network |
none | Only a loopback interface |
Other drivers, such as overlay for several hosts and macvlan for addresses on the physical network, are for larger setups.
Default Bridge vs User-Defined Bridge
The default bridge network exists for compatibility. Containers on it can reach each other only by IP address, and those addresses change when containers are recreated. A bridge network you create yourself adds a built-in DNS server: each container is reachable by its name. It also isolates the group, because containers on different user-defined networks cannot reach each other. For anything beyond a single container, create a network:
docker network create appnet
docker run -d --name db --network appnet -e POSTGRES_PASSWORD=STRONG_PASSWORD postgres:16
docker run -d --name app --network appnet -p 127.0.0.1:3000:3000 myapp:1.0The application now connects to the database at the host name db. Test name resolution from a throwaway container:
docker run --rm --network appnet alpine ping -c 2 dbConnect, Disconnect, and Inspect
docker network connect appnet web
docker network disconnect appnet web
docker network inspect appnetA running container can join or leave a network without a restart, and it can be on several networks at once, for example a reverse proxy that reaches several projects, as in Nginx reverse proxy. inspect shows the subnet, the gateway, and which containers are attached with which address.
The Host Network
docker run -d --name web --network host nginx:stableThe container uses the server's network directly: Nginx listens on port 80 of the server itself. There is no NAT, so -p options are discarded with a warning, and there is no network isolation. Two containers on the host network cannot use the same port. Use it only when a program needs it, for example for network monitoring tools.
The None Network
With --network none, the container has no network at all apart from loopback. It suits batch jobs that process files and must not reach anything.
Networks in Docker Compose
Compose creates a network for each project, named after the project with _default at the end, and attaches every service to it. Services reach each other by service name with no extra setup. You can declare your own networks, for example to keep a database off the network the proxy uses:
services:
proxy:
image: nginx:stable
networks: [front]
app:
image: myapp:1.0
networks: [front, back]
db:
image: postgres:16
networks: [back]
networks:
front:
back:
internal: trueinternal: true creates the network without a connection to the outside world, so db cannot reach the internet; app still can, through front. These networks are removed by docker compose down.
Published Ports and the Firewall
Networks decide how containers talk to each other. Ports decide what the outside world can reach. A port published with -p 8080:80 is opened by Docker's own firewall rules and is reachable from the internet even when UFW denies it; with firewalld, Docker adds a zone and a forwarding policy that let the traffic through as well. Bind internal services to 127.0.0.1, or do not publish them at all when only other containers use them. The details are in Docker port mapping.
Clean Up
docker network rm appnet
docker network pruneA network with attached containers cannot be removed; disconnect or stop them first. prune removes all networks no container uses.
Updated:
Linux VPS with Full Root Access
MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.
More Guides
No Limits on Service or Support
You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

- 100% customer satisfaction goal
- Our own hardware
- 24/7 ticket and email support
- 4 countries with locations