docker network
命令格式:docker network command
Usage: docker network COMMAND
Manage networks
Commands:
connect Connect a container to a network
create Create a network
disconnect Disconnect a container from a network
inspect Display detailed information on one or more networks
ls List networks
prune Remove all unused networks
rm Remove one or more networks
Run 'docker network COMMAND --help' for more information on a command.
create:创建网络
connect:将容器连接到网络上
disconnect:将容器从网络上断开
inspect:查看网络详细信息
prune:删除未使用的网络
rm:删除指定网络
*******************
docker network create
命令格式:docker network create [options] network_name
sage: docker network create [OPTIONS] NETWORK
Create a network
Options:
--attachable Enable manual container attachment
--aux-address map Auxiliary IPv4 or IPv6 addresses used by Network driver (default map[])
--config-from string The network from which copying the configuration
--config-only Create a configuration only network
-d, --driver string Driver to manage the Network (default "bridge")
--gateway strings IPv4 or IPv6 Gateway for the master subnet
--ingress Create swarm routing-mesh network
--internal Restrict external access to the network
--ip-range strings Allocate container ip from a sub-range
--ipam-driver string IP Address Management Driver (default "default")
--ipam-opt map Set IPAM driver specific options (default map[])
--ipv6 Enable IPv6 networking
--label list Set metadata on a network
-o, --opt map Set driver specific options (default map[])
--scope string Control the network's scope
--subnet strings Subnet in CIDR format that represents a network segment
-d:网络驱动,默认为bridge
--subnet strings:设置ip网段
示例
创建网络:docker network create -d overlay --subnet 10.10.0.0/24 my_network
[root@centos docker-swarm]# docker network create -d overlay --subnet 10.10.0.0/24 my_network
3wtwakxnbnly2orj4otigbkxy
创建服务:docker service create --network my_network --replicas 3 --name redis redis
[root@centos docker-swarm]# docker service create --network my_network --replicas 3 --name redis redis
py8515pesfqil4nrmgtxka1ab
overall progress: 3 out of 3 tasks
1/3: running [==================================================>]
2/3: running [==================================================>]
3/3: running [==================================================>]
verify: Service converged
查看服务:docker servce ps redis
[root@centos docker-swarm]# docker service ps redis
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
1ii7nnbuhbef redis.1 redis:latest centos Running Running 6 minutes ago
2ia66det09qt redis.2 redis:latest centos Running Running 6 minutes ago
hspg5zdaoqk5 redis.3 redis:latest centos Running Running 6 minutes ago
查看 ip地址
[root@centos docker-swarm]# docker inspect 76 |grep "IP"
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"IPAMConfig": {
"IPv4Address": "10.10.0.4"
"IPAddress": "10.10.0.4",
"IPPrefixLen": 24,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
[root@centos ~]# docker inspect d6 |grep "IP"
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"IPAMConfig": {
"IPv4Address": "10.10.0.3"
"IPAddress": "10.10.0.3",
"IPPrefixLen": 24,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
[root@centos ~]# docker inspect 6b |grep "IP"
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"IPAMConfig": {
"IPv4Address": "10.10.0.5"
"IPAddress": "10.10.0.5",
"IPPrefixLen": 24,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
ip 地址设置为指定网段范围地址