麦克斯仇
Think different
160
文章
42172
阅读
首页
INDEX
文章
ARTICLE
关于
ABOUT
Docker命令3:docker network(管理网络)
创建日期:
2020/01/09
修改日期:
2023/09/29
Docker
> 以下命令中,若有对 **NETWORK** 操作时,可以写 NETWORK ID 或者 NAME NAME 不可简写,可以写几个字母后使用`tab`键自动补全, NETWORK ID 可以简写,简写至可以唯一确定即可,简写规则同容器简写规则 ### create 创建一个网络 ```bash docker network create [OPTIONS] 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") # 管理网络的驱动程序(默认 bridge ) 可选值:bridge ipvlan macvlan overlay --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 ``` ```bash # 创建一个网络,指定驱动为 bridge docker network create -d bridge mybridge ``` ### ls 网络列表 ```bash docker network ls [OPTIONS] Options: -f, --filter filter Provide filter values (e.g. 'driver=bridge') --format string Pretty-print networks using a Go template --no-trunc Do not truncate the output -q, --quiet Only display network IDs ``` ```bash # 网络列表 docker network ls # 列出driver为bridge的网络 docker network ls -f driver=bridge ``` 列 | 说明 | 注 ---|---|--- NETWORK ID | ID | --no-trunc 显示完整ID NAME | 名称 | DRIVER | 驱动 | SCOPE | 范围 | ### inspect 显示一个或多个网络上的详细信息 ```bash docker network inspect [OPTIONS] NETWORK [NETWORK...] # 此命令可以简写如下命令,但是 docker inspect 不仅仅可以查看 NETWORK docker inspect [OPTIONS] NAME|ID [NAME|ID...] Options: -f, --format string Format the output using the given Go template -v, --verbose Verbose output for diagnostics ``` ```bash # 显示bridge网络详细信息 docker network inspect bridge ``` > inspect详细内容后期整理 ### rm 删除一个或多个网络 ```bash docker network rm NETWORK [NETWORK...] ``` ```bash # 移除自己创建的网络 # docker创建好后默认创建的 bridge host none 网络无法移除 docker network rm mybridge ``` ### prune 删除所有未使用的网络 ```bash docker network prune [OPTIONS] Options: --filter filter Provide filter values (e.g. 'until=<timestamp>') -f, --force Do not prompt for confirmation # 不提示确认 ``` ```bash # 移除所有未使用的网络(-f 不提示确认) docker network prune -f ``` ### connect 将容器连接到网络 ```bash docker network connect [OPTIONS] NETWORK CONTAINER Options: --alias strings Add network-scoped alias for the container --driver-opt strings driver options for the network --ip string IPv4 address (e.g., 172.30.100.104) --ip6 string IPv6 address (e.g., 2001:db8::33) --link list Add link to another container --link-local-ip strings Add a link-local address for the container ``` ```bash # 将test1容器连接到自己创建的mybridge网络 docker network connect mybridge test1 ``` ### disconnect 断开容器与网络的连接 ```bash docker network disconnect [OPTIONS] NETWORK CONTAINER Options: -f, --force Force the container to disconnect from a network # 强制容器断开与网络的连接 ``` ```bash # 将test1容器与默认网络断开连接 docker network disconnect bridge test1 ```
11
全部评论