目录 搜索
Compose About versions and upgrading (Compose) ASP.NET Core + SQL Server on Linux (Compose) CLI environment variables (Compose) Command-line completion (Compose) Compose(组成) Compose command-line reference(组合命令行参考) Control startup order (Compose) Django and PostgreSQL (Compose) Docker stacks and distributed application bundles (Compose) docker-compose build(docker-compose构建) docker-compose bundle docker-compose config docker-compose create docker-compose down docker-compose events docker-compose exec docker-compose help docker-compose images docker-compose kill docker-compose logs docker-compose pause docker-compose port docker-compose ps docker-compose pull docker-compose push docker-compose restart docker-compose rm docker-compose run docker-compose scale docker-compose start docker-compose stop docker-compose top docker-compose unpause docker-compose up Environment file (Compose) Environment variables in Compose Extend services in Compose Frequently asked questions (Compose) Getting started (Compose) Install Compose Link environment variables (deprecated) (Compose) Networking in Compose Overview of Docker Compose Overview of docker-compose CLI Quickstart: Compose and WordPress Rails and PostgreSQL (Compose) Sample apps with Compose Using Compose in production Using Compose with Swarm Engine .NET Core application (Engine) About images, containers, and storage drivers (Engine) Add nodes to the swarm (Engine) Apply custom metadata (Engine) Apply rolling updates (Engine) apt-cacher-ng Best practices for writing Dockerfiles (Engine) Binaries (Engine) Bind container ports to the host (Engine) Breaking changes (Engine) Build your own bridge (Engine) Configure container DNS (Engine) Configure container DNS in user-defined networks (Engine) CouchDB (Engine) Create a base image (Engine) Create a swarm (Engine) Customize the docker0 bridge (Engine) Debian (Engine) Default bridge network Delete the service (Engine) Deploy a service (Engine) Deploy services to a swarm (Engine) Deprecated Engine features Docker container networking (Engine) Docker overview (Engine) Docker run reference (Engine) Dockerfile reference (Engine) Dockerize an application Drain a node (Engine) Engine FAQ (Engine) Fedora (Engine) Get started (Engine) Get started with macvlan network driver (Engine) Get started with multi-host networking (Engine) How nodes work (Engine) How services work (Engine) Image management (Engine) Inspect the service (Engine) Install Docker (Engine) IPv6 with Docker (Engine) Join nodes to a swarm (Engine) Legacy container links (Engine) Lock your swarm (Engine) Manage nodes in a swarm (Engine) Manage sensitive data with Docker secrets (Engine) Manage swarm security with PKI (Engine) Manage swarm service networks (Engine) Migrate to Engine 1.10 Optional Linux post-installation steps (Engine) Overview (Engine) PostgreSQL (Engine) Raft consensus in swarm mode (Engine) Riak (Engine) Run Docker Engine in swarm mode Scale the service (Engine) SDKs (Engine) Select a storage driver (Engine) Set up for the tutorial (Engine) SSHd (Engine) Storage driver overview (Engine) Store service configuration data (Engine) Swarm administration guide (Engine) Swarm mode key concepts (Engine) Swarm mode overlay network security model (Engine) Swarm mode overview (Engine) Understand container communication (Engine) Use multi-stage builds (Engine) Use swarm mode routing mesh (Engine) Use the AUFS storage driver (Engine) Use the Btrfs storage driver (Engine) Use the Device mapper storage driver (Engine) Use the OverlayFS storage driver (Engine) Use the VFS storage driver (Engine) Use the ZFS storage driver (Engine) Engine: Admin Guide Amazon CloudWatch logs logging driver (Engine) Bind mounts (Engine) Collect Docker metrics with Prometheus (Engine) Configuring and running Docker (Engine) Configuring logging drivers (Engine) Control and configure Docker with systemd (Engine) ETW logging driver (Engine) Fluentd logging driver (Engine) Format command and log output (Engine) Google Cloud logging driver (Engine) Graylog Extended Format (GELF) logging driver (Engine) Journald logging driver (Engine) JSON File logging driver (Engine) Keep containers alive during daemon downtime (Engine) Limit a container's resources (Engine) Link via an ambassador container (Engine) Log tags for logging driver (Engine) Logentries logging driver (Engine) PowerShell DSC usage (Engine) Prune unused Docker objects (Engine) Run multiple services in a container (Engine) Runtime metrics (Engine) Splunk logging driver (Engine) Start containers automatically (Engine) Storage overview (Engine) Syslog logging driver (Engine) tmpfs mounts Troubleshoot volume problems (Engine) Use a logging driver plugin (Engine) Using Ansible (Engine) Using Chef (Engine) Using Puppet (Engine) View a container's logs (Engine) Volumes (Engine) Engine: CLI Daemon CLI reference (dockerd) (Engine) docker docker attach docker build docker checkpoint docker checkpoint create docker checkpoint ls docker checkpoint rm docker commit docker config docker config create docker config inspect docker config ls docker config rm docker container docker container attach docker container commit docker container cp docker container create docker container diff docker container exec docker container export docker container inspect docker container kill docker container logs docker container ls docker container pause docker container port docker container prune docker container rename docker container restart docker container rm docker container run docker container start docker container stats docker container stop docker container top docker container unpause docker container update docker container wait docker cp docker create docker deploy docker diff docker events docker exec docker export docker history docker image docker image build docker image history docker image import docker image inspect docker image load docker image ls docker image prune docker image pull docker image push docker image rm docker image save docker image tag docker images docker import docker info docker inspect docker kill docker load docker login docker logout docker logs docker network docker network connect docker network create docker network disconnect docker network inspect docker network ls docker network prune docker network rm docker node docker node demote docker node inspect docker node ls docker node promote docker node ps docker node rm docker node update docker pause docker plugin docker plugin create docker plugin disable docker plugin enable docker plugin inspect docker plugin install docker plugin ls docker plugin push docker plugin rm docker plugin set docker plugin upgrade docker port docker ps docker pull docker push docker rename docker restart docker rm docker rmi docker run docker save docker search docker secret docker secret create docker secret inspect docker secret ls docker secret rm docker service docker service create docker service inspect docker service logs docker service ls docker service ps docker service rm docker service scale docker service update docker stack docker stack deploy docker stack ls docker stack ps docker stack rm docker stack services docker start docker stats docker stop docker swarm docker swarm ca docker swarm init docker swarm join docker swarm join-token docker swarm leave docker swarm unlock docker swarm unlock-key docker swarm update docker system docker system df docker system events docker system info docker system prune docker tag docker top docker unpause docker update docker version docker volume docker volume create docker volume inspect docker volume ls docker volume prune docker volume rm docker wait Use the Docker command line (Engine) Engine: Extend Access authorization plugin (Engine) Docker log driver plugins Docker network driver plugins (Engine) Extending Engine with plugins Managed plugin system (Engine) Plugin configuration (Engine) Plugins API (Engine) Volume plugins (Engine) Engine: Security AppArmor security profiles for Docker (Engine) Automation with content trust (Engine) Content trust in Docker (Engine) Delegations for content trust (Engine) Deploying Notary (Engine) Docker security (Engine) Docker security non-events (Engine) Isolate containers with a user namespace (Engine) Manage keys for content trust (Engine) Play in a content trust sandbox (Engine) Protect the Docker daemon socket (Engine) Seccomp security profiles for Docker (Engine) Secure Engine Use trusted images Using certificates for repository client verification (Engine) Engine: Tutorials Engine tutorials Network containers (Engine) Get Started Part 1: Orientation Part 2: Containers Part 3: Services Part 4: Swarms Part 5: Stacks Part 6: Deploy your app Machine Amazon Web Services (Machine) Digital Ocean (Machine) docker-machine active docker-machine config docker-machine create docker-machine env docker-machine help docker-machine inspect docker-machine ip docker-machine kill docker-machine ls docker-machine provision docker-machine regenerate-certs docker-machine restart docker-machine rm docker-machine scp docker-machine ssh docker-machine start docker-machine status docker-machine stop docker-machine upgrade docker-machine url Driver options and operating system defaults (Machine) Drivers overview (Machine) Exoscale (Machine) Generic (Machine) Get started with a local VM (Machine) Google Compute Engine (Machine) IBM Softlayer (Machine) Install Machine Machine Machine CLI overview Machine command-line completion Machine concepts and help Machine overview Microsoft Azure (Machine) Microsoft Hyper-V (Machine) Migrate from Boot2Docker to Machine OpenStack (Machine) Oracle VirtualBox (Machine) Provision AWS EC2 instances (Machine) Provision Digital Ocean Droplets (Machine) Provision hosts in the cloud (Machine) Rackspace (Machine) VMware Fusion (Machine) VMware vCloud Air (Machine) VMware vSphere (Machine) Notary Client configuration (Notary) Common Server and signer configurations (Notary) Getting started with Notary Notary changelog Notary configuration files Running a Notary service Server configuration (Notary) Signer configuration (Notary) Understand the service architecture (Notary) Use the Notary client
文字

描述

创建网络

用法

docker network create [OPTIONS] NETWORK

选项

名称,简写

默认

描述

--attachable

false

启用手动容器附件

--aux地址

map[]

网络驱动程序使用的辅助IPv4或IPv6地址

--config-from


从中复制配置的网络

--config-only

false

创建一个仅配置网络

--driver,-d

bridge

驱动程序来管理网络

--gateway


主子网的IPv4或IPv6网关

--ingress

false

创建群体路由网状网络

--internal

false

限制对网络的外部访问

--ip-range


从子范围分配容器IP

--ipam-driver

default

IP地址管理驱动程序

--ipam-opt

map[]

设置IPAM驱动程序特定选项

--ipv6

false

启用IPv6网络

--label


在网络上设置元数据

--opt, -o

map[]

设置驱动程序特定选项

--scope


控制网络的范围

--subnet


表示网段的CIDR格式的子网

父命令

命令

描述

docker网络

管理网络

相关命令

命令

描述

docker network connect

将容器连接到网络

docker network create

创建一个网络

docker network disconnect

从网络断开容器

docker network inspect

显示一个或多个网络的详细信息

docker network ls

列出网络

docker network prune

删除所有未使用的网络

docker network rm

删除一个或多个网络

扩展描述

创建一个新的网络。在DRIVER接受bridge或者overlay它们是内置的网络驱动程序。如果您已经安装了第三方或您自己的自定义网络驱动程序,您也可以DRIVER在此处指定。如果您不指定该--driver选项,该命令将自动bridge为您创建一个网络。当您安装Docker Engine时,它会bridge自动创建一个网络。该网络对应于docker0引擎传统依赖的桥梁。当你启动一个新的容器时,docker run它会自动连接到这个网桥。您无法删除此默认桥接网络,但可以使用该network create命令创建新桥接网络。

$ docker network create -d bridge my-bridge-network

桥接网络是单个引擎安装中的隔离网络。如果您想创建一个跨多个运行引擎的多个Docker主机的overlay网络,则必须创建一个网络。与bridge网络不同,覆盖网络在创建之前需要一些预先存在的条件。这些条件是:

  • 访问键值存储。引擎支持Consul,Etcd和ZooKeeper(分布式存储)键值存储。

  • 连接到键值存储的主机集群。

  • daemon集群中每台主机上配置正确的引擎。

dockerd支持overlay网络的选项有:

  • --cluster-store

  • --cluster-store-opt

  • --cluster-advertise

要详细了解这些选项以及如何配置它们,请参阅“ 多主机网络入门 ”。

虽然不是必需的,但安装Docker Swarm来管理组成网络的集群是一个不错的主意。Swarm提供了复杂的发现和服务器管理工具,可以帮助您实施。

准备好overlay网络先决条件后,只需在集群中选择Docker主机并发出以下命令即可创建网络:

$ docker network create -d overlay my-multihost-network

网络名称必须是唯一的。Docker守护进程尝试识别命名冲突,但不能保证。避免名称冲突是用户的责任。

实例

连接容器

当您启动容器时,请使用--network标志将其连接到网络。本例将busybox容器添加到mynet网络中:

$ docker run -itd --network=mynet busybox

如果要在容器已经运行后将容器添加到网络,请使用docker network connect子命令。

您可以将多个容器连接到同一个网络。连接后,容器只能使用另一个容器的IP地址或名称进行通信。对于overlay支持多主机连接的网络或自定义插件,连接到相同多主机网络但从不同引擎启动的容器也可以通过这种方式进行通信。

您可以使用该docker network disconnect命令从网络断开容器。

指定高级选项

在创建网络时,Engine默认会为网络创建一个不重叠的子网。这个子网不是现有网络的细分。这纯粹是为了ip地址的目的。您可以覆盖此默认值并直接使用--subnet选项指定子网值。在bridge网络上,您只能创建一个子网:

$ docker network create --driver=bridge --subnet=192.168.0.0/16 br0

另外,您还可以指定--gateway --ip-range--aux-address选项。

$ docker network create \  --driver=bridge \  --subnet=172.28.0.0/16 \  --ip-range=172.28.5.0/24 \  --gateway=172.28.5.254 \
  br0

如果您省略--gateway标志,引擎会从首选池中为您选择一个。对于overlay网络和支持它的网络驱动程序插件,您可以创建多个子网。

$ docker network create -d overlay \  --subnet=192.168.0.0/16 \  --subnet=192.170.0.0/16 \  --gateway=192.168.0.100 \  --gateway=192.170.0.100 \  --ip-range=192.168.1.0/24 \  --aux-address="my-router=192.168.1.5" --aux-address="my-switch=192.168.1.6" \  --aux-address="my-printer=192.170.1.5" --aux-address="my-nas=192.170.1.6" \
  my-multihost-network

确保你的子网不重叠。如果他们这样做,网络创建失败,引擎返回错误。

桥接司机选项

在创建自定义网络时,默认网络驱动程序(即bridge)具有可以传递的其他选项。以下是用于docker0桥的那些选项和等效的docker守护进程标志:

选项

当量

描述

com.docker.network.bridge.name

-

在创建Linux桥时要使用的桥名称

com.docker.network.bridge.enable_ip_masquerade

--ip-masq

启用IP伪装

com.docker.network.bridge.enable_icc

--icc

启用或禁用集装箱间连接

com.docker.network.bridge.host_binding_ipv4

--ip

绑定容器端口时的默认IP

com.docker.network.driver.mtu

--mtu

设置容器网络MTU

以下参数可以传递给docker network create任何网络驱动程序,同样也可以传递给它们的近似等价物docker daemon

论据

当量

描述

--gateway

-

主子网的IPv4或IPv6网关

--ip范围

--fixed,CIDR

从一个范围分配IP

- 内部

-

限制对网络的外部访问

--ipv6

--ipv6

启用IPv6网络

--subnet

--bip

网络子网

例如,让我们使用-o--opt在发布端口时指定IP地址绑定的选项:

$ docker network create \    -o "com.docker.network.bridge.host_binding_ipv4"="172.19.0.1" \
    simple-network

网络内部模式

默认情况下,当您将容器连接到overlay网络时,Docker也会将桥接网络连接到它以提供外部连接。如果您想创建一个外部隔离的overlay网络,您可以指定该--internal选项。

网络入口模式

您可以创建将用于在群集中提供路由网格的网络。您可以通过--ingress在创建网络时指定。当时只能创建一个入口网络。只有在没有服务依赖它的情况下才能删除网络。除了--attachable选项之外,创建入口网络时创建覆盖网络时可用的任何选项也可用。

$ docker network create -d overlay \  --subnet=10.11.0.0/16 \  --ingress \  --opt com.docker.network.mtu=9216 \  --opt encrypted=true \
  my-ingress-network
上一篇: 下一篇: