docker network Explained

What docker network does, with an example.

Published November 9, 2026

Docker networks let containers talk to each other. Containers on the same user-defined network can reach each other by name through built-in DNS.

How it works

Drivers: bridge (default, single host), host (shares the host network), overlay (multi-host) and none.

Publishing a port (-p) exposes a container to the outside; internal traffic does not need it.

Try it

docker network create app-net
docker run -d --network app-net --name db postgres
docker run --network app-net curlimages/curl curl db:5432

Practical examples

Create and attach

docker network create app-net
docker run -d --network app-net --name api myapi

Inspect

docker network inspect app-net

Connect a running container

docker network connect app-net web

List

docker network ls

Common mistakes

  • Using the default bridge where name resolution doesn't work.
  • Publishing database ports unnecessarily.
  • Using localhost to reach other containers.

Key takeaways

  • Docker networks let containers talk to each other.
  • Run docker <command> --help for all options.
  • Clean up unused resources regularly.

FAQ

Why can't containers resolve names?

Names only work on user-defined networks, not the default bridge.

Where can I see all options?

Run the command with --help.

More General articles