arrow_back
Back

Docker network commands: create, connect, and inspect

Andrew Dorokhov Andrew Dorokhov schedule 1 min read
menu_book Table of Contents

docker network ls

List networks.

docker network ls

docker network create

Create a network. Default driver is bridge.

docker network create <NETWORK_NAME>

Parameters

  • --subnet <SUBNET> — specific subnet.
  • --gateway <GATEWAY> — specific gateway.
  • --ip-range=<IP_RANGE> — IP range for containers.
  • --driver=<DRIVER> — network driver.
  • --internal — create an internal network with no external routing.

Example:

docker network create --subnet 10.1.0.0/24 --gateway 10.1.0.1 websites

After creation, ifconfig on the host shows the network as interface br-<NETWORK_ID>.

Overlay networks

docker network create -d overlay <NETWORK_NAME>
docker network create -d overlay --opt encrypted <NETWORK_NAME>

docker network connect / disconnect

Add or remove a container from a network.

docker network connect <NETWORK> <CONTAINER>
docker network disconnect <NETWORK> <CONTAINER>

docker network inspect

Display detailed network information.

docker network inspect <NETWORK_ID>

An "Options": { "encrypted": "" } entry indicates an encrypted overlay network.

docker network rm

Remove a network.

docker network rm <NETWORK_NAME>

docker network prune

Remove all unused networks.

docker network prune
code

Need Help with Development?

Happy to help — reach out via the contacts or go straight to my Upwork profile.

work View Upwork Profile arrow_forward
Next Article

Docker Machine: provisioning and managing Docker hosts

arrow_forward