docker network Command
docker network The command is used to manage Docker networks. These commands can create, list, delete, and inspect networks, helping users establish communication between Docker containers.
Common docker network Command
docker network ls: List all networksdocker network inspect: View detailed network informationdocker network create: Create a new networkdocker network rm: Delete one or more networksdocker network connect: Connect a container to a networkdocker network disconnect: Disconnect a container from a network
docker network ls Command
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 inspect Command
View detailed information of a 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 create Command
Create a new network.
docker network create my_network
Common parameters
--driver: Specify the network driver (such asbridge、host、overlay)。--subnet: Specify the subnet.--gateway: Specify the gateway.--ip-range: Specify 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 rm Command
Delete one or more networks.
docker network rm my_network
Delete multiple networks:
docker network rm network1 network2
docker network connect Command
Connect a container to a network.
docker network connect my_network my_container
docker network disconnect Command
Disconnect a container from a network.
docker network disconnect my_network my_container
Use Cases
- Inter-container communication: Through custom networks, containers can communicate with each other securely across different hosts.
- Isolated environments: Use different networks to isolate container environments and improve security.
- Advanced network configuration: Use network drivers such as bridge and overlay to implement complex network topologies.
docker network The command set provides powerful network management functions, 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 to meet various complex networking needs.
Docker Command Reference