Join our Discord Server

Docker Networking Cheatsheet

← All cheatsheets
CoreIntermediate

Docker Networking Cheatsheet

Connect containers with bridge, overlay, and host networks. Expose ports and manage DNS.


What it is

Docker networking allows containers to communicate with each other and the outside world using multiple drivers: bridge (default), host, overlay (Swarm), macvlan, and none.

Installation

Built into Docker Engine. No additional installation needed.

Quick start

docker network create mynet

Create a custom bridge network.

docker run --network mynet myimage

Connect a container to a network.

docker network ls

List all networks.

Common commands

TaskCommandDescription
Create networkdocker network create <name>Create a new bridge network.
List networksdocker network lsShow all Docker networks.
Inspect networkdocker network inspect <name>Show containers, IPAM config, drivers.
Connect containerdocker network connect <net> <ctr>Attach a running container to a network.
Disconnectdocker network disconnect <net> <ctr>Remove a container from a network.
Remove networkdocker network rm <name>Delete a network (no active containers).
Prune networksdocker network pruneRemove all unused networks.
Publish portdocker run -p 8080:80 nginxMap host port 8080 to container port 80.

Real-world examples

Isolated network for a multi-container app
docker network create appnet
docker run -d --name db --network appnet postgres:16
docker run -d --name api --network appnet -p 3000:3000 myapi

Best practices

  • Always create custom networks for multi-container apps instead of using the default bridge.
  • Use container names as hostnames within the same network — Docker provides automatic DNS.
  • Remove unused networks with docker network prune to keep the host tidy.

Related cheatsheets


Last reviewed: 2026-06-15
Join our Discord Server