Docker命令-network

命令

docker network

描述

Manage networks
网络管理

用法

1
2
3
4
5
6
7
docker network connect [OPTIONS] NETWORK CONTAINER
docker network create [OPTIONS] NETWORK
docker network disconnect [OPTIONS] NETWORK CONTAINER
docker network inspect [OPTIONS] NETWORK [NETWORK...]
docker network ls [OPTIONS]
docker network prune [OPTIONS]
docker network rm NETWORK [NETWORK...]

选项

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Options:
docker network connect Connect a container to a network
docker network create Create a network
docker network disconnect Disconnect a container from a network
docker network inspect Display detailed information on one or more networks
docker network ls List networks
docker network prune Remove all unused networks
docker network rm Remove one or more networks

connect Options:
--alias Add network-scoped alias for the container
--driver-opt driver options for the network
--ip IPv4 address
--ip6 IPv6 address
--link Add link to another container
--link-local-ip Add a link-local address for the container

create Options:
--attachable Enable manual container attachment
--aux-address Auxiliary IPv4 or IPv6 addresses used by Network driver
--config-from The network from which to copy the configuration
--config-only Create a configuration only network
--driver , -d Driver to manage the Network, default is bridge
--gateway IPv4 or IPv6 Gateway for the master subnet
--ingress Create swarm routing-mesh network
--internal Restrict external access to the network
--ip-range Allocate container ip from a sub-range
--ipam-driver IP Address Management Driver
--ipam-opt Set IPAM driver specific options
--ipv6 Enable IPv6 networking
--label Set metadata on a network
--opt , -o Set driver specific options
--scope Control the network's scope
--subnet Subnet in CIDR format that represents a network segment

disconnect Options:
--force , -f Force the container to disconnect from a network

inspect Options:
--format , -f Format the output using the given Go template
--verbose , -v Verbose output for diagnostics

ls Options:
--filter , -f Provide filter values (e.g. 'driver=bridge')
--format Pretty-print networks using a Go template
--no-trunc Do not truncate the output
--quiet , -q Only display network IDs

prune Options:
--filter Provide filter values (e.g. 'until=<timestamp>')
--force , -f Do not prompt for confirmation

注意

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 创建网络
$ docker network create --driver=bridge --subnet=172.16.0.0/16 mynet
# 连接运行的容器到指定网络
$ docker network connect mynet nginx
# 创建容器时指定网络
$ docker run -itd --network=mynet nginx
# 创建网络时指定子网和网关等信息
$ docker network create \
--driver=bridge \
--subnet=172.28.0.0/16 \
--ip-range=172.28.5.0/24 \
--gateway=172.28.5.254 \
br0
# 断开容器网络连接
$ docker network disconnect mynet nginx
$ docker network ls
$ docker network ls --no-trunc
$ docker network ls --filter driver=bridge
$ docker network ls --filter name=net
$ docker network ls --format "{{.ID}}: {{.Driver}}"

$ docker network prune
$ docker network prune --force --filter until=5m
$ docker network rm mynet