Docker

Docker Network CLI

Docker network commands for container networking.

28 commands
Windows MacOS Linux
#networking #containers

Network Management

List all networks
docker network ls
Create a bridge network
docker network create mynet
Create an overlay network
docker network create --driver overlay mynet
Remove a network
docker network rm mynet
Remove all unused networks
docker network prune
Create network with subnet
docker network create --subnet=172.20.0.0/16 mynet

Connection

Connect container to network
docker network connect mynet mycontainer
Disconnect container from network
docker network disconnect mynet mycontainer
Run container on specific network
docker run --network mynet nginx
Run with specific IP
docker run --network mynet --ip 172.20.0.10 nginx
Run container with host networking
docker run --network host nginx

Inspection

Show detailed network info
docker network inspect mynet
Inspect default bridge network
docker network inspect bridge
Show container networks
docker inspect --format '{{json .NetworkSettings.Networks}}' mycontainer
List containers on network
docker network inspect mynet --format '{{range .Containers}}{{.Name}} {{end}}'

Drivers

Create bridge network explicitly
docker network create --driver bridge mybridge
Create host network
docker network create --driver host myhost
Create network with no connectivity
docker network create --driver none mynone
Create attachable overlay
docker network create --driver overlay --attachable myoverlay
Create internal-only network
docker network create --internal myinternal

Troubleshooting

Test connectivity between containers
docker run --rm --network mynet busybox ping -c 3 mycontainer
Test DNS resolution
docker run --rm --network mynet busybox nslookup mycontainer
Check container hosts file
docker exec mycontainer cat /etc/hosts
Show container network interfaces
docker exec mycontainer ip addr show
Run network diagnostics
docker run --rm --network mynet nicolaka/netshoot iperf3 -c target

Quick Commands

List all Docker networks
docker network ls
Create a new Docker network
docker network create <name>
Connect a running container to a network
docker network connect <network> <container>