Docker Networking Basics
This page is a hands-on intro to Docker's built-in network drivers - bridge, host, and none - and to publishing ports so the outside world can reach a container.
Search across all documentation pages
This page is a hands-on intro to Docker's built-in network drivers - bridge, host, and none - and to publishing ports so the outside world can reach a container.
Everything here is single-host Docker Engine; Kubernetes networking is a separate model covered elsewhere.
docker compose, not the legacy docker-compose).docker without extra privileges.docker version --format '{{.Server.Version}}'
docker network lsEvery install ships with three networks you cannot delete.
docker network lsbridge is the default network containers join when you pass no --network.host shares the host's network namespace directly.none gives a container no network at all.A plain docker run attaches to the default bridge.
docker run -d --name web nginx:1.27
docker inspect -f '{{.NetworkSettings.IPAddress}}' webdocker0 subnet.Publishing maps a host port to a container port with a DNAT rule.
docker run -d -p 8080:80 --name web nginx:1.27
curl -s http://localhost:8080 | head -n1-p 8080:80 forwards host 8080 to container 80.EXPOSE in a Dockerfile is only documentation; it does not publish anything.-p 127.0.0.1:8080:80 to avoid exposing publicly.-P to publish all exposed ports to random high host ports.The host driver skips the network namespace entirely.
docker run -d --network host --name metrics prom/node-exporter:v1.8.2-p is needed or allowed.host is Linux-native; on Docker Desktop it behaves differently.The none driver creates an isolated stack with only loopback.
docker run --rm --network none alpine:3.20 ip addrlo interface exists inside the container.docker network connect.docker network inspect shows the subnet, gateway, and connected containers.
docker network inspect bridgeContainers map lists every attached container and its IP.IPAM shows the subnet and gateway the driver allocated.--format lets you pull a single field for scripts.Check what a container actually published with docker port.
docker port web-P and got random host ports.ss -tlnp on the host to see the listener.Custom bridges add automatic name resolution the default bridge lacks.
docker network create appnet
docker run -d --network appnet --name api myapi:1.0
docker run --rm --network appnet alpine:3.20 ping -c1 apiappnet can reach api.127.0.0.11 inside the container.A container can join several networks for segmentation.
docker network create frontend
docker network create backend
docker run -d --name app --network frontend myapp:1.0
docker network connect backend appapp can now reach services on both frontend and backend.docker network disconnect backend app.Compose declares ports and networks in one file.
services:
web:
image: nginx:1.27
ports:
- "127.0.0.1:8080:80"
networks:
- appnet
networks:
appnet:appnet automatically and joins web to it.127.0.0.1: prefix keeps the port off public interfaces.docker compose up -d.When a connection fails, test from the container's own namespace, not the host.
docker run --rm --network appnet nicolaka/netshoot \
sh -c 'nslookup api; nc -zv api 80'netshoot bundles dig, nc, curl, and tcpdump for network debugging.nslookup confirms whether embedded DNS resolves the target name.nc -zv proves whether the port is actually open and reachable.Stack versions: This page was written for Kubernetes 1.36.2, Docker Engine 29.6.1 (BuildKit default), containerd (CRI runtime on nodes), Helm 3, Compose v2, Argo CD (latest - verify at build), and Gateway API (GA - verify controller support at build).
Reviewed by Chris St. John·Last updated Jul 16, 2026