Advertisement

List Networks

Show all Docker networks.

docker network ls

Create Network

Create a new network.

docker network create <network-name>

Create with specific driver:

docker network create --driver bridge my-network

Create with subnet:

docker network create --subnet=172.18.0.0/16 my-network

Inspect Network

View detailed network information.

docker network inspect <network-name>

Connect Container to Network

Connect running container to network.

docker network connect <network-name> <container-name>

Connect with alias:

docker network connect --alias db-server my-network my-container

Disconnect Container

Disconnect container from network.

docker network disconnect <network-name> <container-name>
Advertisement

Remove Network

Delete a network.

docker network rm <network-name>

Remove all unused networks:

docker network prune

Run Container on Network

Start container connected to specific network.

docker run --network=<network-name> image-name

Example:

docker run --network=my-network --name web nginx

Network Drivers

Bridge (default) - isolated network on single host:

docker network create --driver bridge my-bridge

Host - use host's network stack:

docker run --network=host nginx

None - no networking:

docker run --network=none nginx

Overlay - multi-host networking:

docker network create --driver overlay my-overlay

DNS Resolution

Containers on same user-defined network can resolve each other by name.

docker network create app-network
docker run --network=app-network --name database postgres
docker run --network=app-network --name web nginx
# web can reach database via hostname "database"

Publish Ports

Map container port to host port.

docker run -p 8080:80 --network=my-network nginx

Map all exposed ports:

docker run -P --network=my-network nginx

Network Configuration

Set DNS servers:

docker run --dns=8.8.8.8 --network=my-network nginx

Set hostname:

docker run --hostname=myhost --network=my-network nginx
Last updated: January 2026
Advertisement