docker network command

Docker command reference


docker networkThe command is used to manage Docker networks. These commands can create, list, delete, and inspect networks, helping users establish communication between Docker containers.

Commondocker networkCommand

  1. docker network ls: List all networks
  2. docker network inspect: View detailed information about a network
  3. docker network create: Create a new network
  4. docker network rm: Delete one or more networks
  5. docker network connect: Connect a container to a network
  6. docker network disconnect: Disconnect a container from a network

docker network lsCommand

List all networks.

docker network ls

Output:

NETWORK ID          NAME                DRIVER              SCOPE
b649b57f5bc5        bridge              bridge              local
7e8c2d2c0b5a        host                host                local
6a9c8d69bfb2        none                null                local

docker network inspectCommand

View detailed information about the specified network.

Output:

[
    {
        "Name": "my_network",
        "Id": "b649b57f5bc5",
        "Created": "2024-07-23T00:00:00.000000000Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.18.0.0/16",
                    "Gateway": "172.18.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Containers": {},
        "Options": {},
        "Labels": {}
    }
]

docker network createCommand

Create a new network.

docker network create my_network

Common Parameters

  • --driver: Specify the network driver (e.g.,bridge、host、overlay)。
  • --subnet: Specify subnet.
  • --gateway: Specify gateway.
  • --ip-rangeSpecify the available IP address range.
  • --ipv6: Enable IPv6.
  • --label: Add labels to the network.

Example:

docker network create --driver bridge --subnet 192.168.1.0/24 my_network

docker network rmCommand

Delete one or more networks.

docker network rm my_network

Delete multiple networks:

docker network rm network1 network2

docker network connectCommand

Connect a container to a network.

docker network connect my_network my_container

docker network disconnectCommand

Disconnect a container from a network.

docker network disconnect my_network my_container

Use Case

  • Inter-container communicationThrough custom networks, containers can securely communicate with each other on different hosts.
  • Isolated environmentUse different networks to isolate container environments and improve security.
  • Advanced network configurationUse network drivers such as bridge and overlay to implement complex network topologies.

docker networkThe command set provides powerful network management capabilities, allowing users to create, configure, and manage network connections between Docker containers. By using these commands, users can achieve isolation, communication, and network configuration between containers, meeting various complex network requirements.


Docker command reference

other extensions