目录搜索
ComposeAbout 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 bundledocker-compose configdocker-compose createdocker-compose downdocker-compose eventsdocker-compose execdocker-compose helpdocker-compose imagesdocker-compose killdocker-compose logsdocker-compose pausedocker-compose portdocker-compose psdocker-compose pulldocker-compose pushdocker-compose restartdocker-compose rmdocker-compose rundocker-compose scaledocker-compose startdocker-compose stopdocker-compose topdocker-compose unpausedocker-compose upEnvironment file (Compose)Environment variables in ComposeExtend services in ComposeFrequently asked questions (Compose)Getting started (Compose)Install ComposeLink environment variables (deprecated) (Compose)Networking in ComposeOverview of Docker ComposeOverview of docker-compose CLIQuickstart: Compose and WordPressRails and PostgreSQL (Compose)Sample apps with ComposeUsing Compose in productionUsing Compose with SwarmEngine.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-ngBest 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 networkDelete the service (Engine)Deploy a service (Engine)Deploy services to a swarm (Engine)Deprecated Engine featuresDocker container networking (Engine)Docker overview (Engine)Docker run reference (Engine)Dockerfile reference (Engine)Dockerize an applicationDrain a node (Engine)EngineFAQ (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.10Optional Linux post-installation steps (Engine)Overview (Engine)PostgreSQL (Engine)Raft consensus in swarm mode (Engine)Riak (Engine)Run Docker Engine in swarm modeScale 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 GuideAmazon 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 mountsTroubleshoot 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: CLIDaemon CLI reference (dockerd) (Engine)dockerdocker attachdocker builddocker checkpointdocker checkpoint createdocker checkpoint lsdocker checkpoint rmdocker commitdocker configdocker config createdocker config inspectdocker config lsdocker config rmdocker containerdocker container attachdocker container commitdocker container cpdocker container createdocker container diffdocker container execdocker container exportdocker container inspectdocker container killdocker container logsdocker container lsdocker container pausedocker container portdocker container prunedocker container renamedocker container restartdocker container rmdocker container rundocker container startdocker container statsdocker container stopdocker container topdocker container unpausedocker container updatedocker container waitdocker cpdocker createdocker deploydocker diffdocker eventsdocker execdocker exportdocker historydocker imagedocker image builddocker image historydocker image importdocker image inspectdocker image loaddocker image lsdocker image prunedocker image pulldocker image pushdocker image rmdocker image savedocker image tagdocker imagesdocker importdocker infodocker inspectdocker killdocker loaddocker logindocker logoutdocker logsdocker networkdocker network connectdocker network createdocker network disconnectdocker network inspectdocker network lsdocker network prunedocker network rmdocker nodedocker node demotedocker node inspectdocker node lsdocker node promotedocker node psdocker node rmdocker node updatedocker pausedocker plugindocker plugin createdocker plugin disabledocker plugin enabledocker plugin inspectdocker plugin installdocker plugin lsdocker plugin pushdocker plugin rmdocker plugin setdocker plugin upgradedocker portdocker psdocker pulldocker pushdocker renamedocker restartdocker rmdocker rmidocker rundocker savedocker searchdocker secretdocker secret createdocker secret inspectdocker secret lsdocker secret rmdocker servicedocker service createdocker service inspectdocker service logsdocker service lsdocker service psdocker service rmdocker service scaledocker service updatedocker stackdocker stack deploydocker stack lsdocker stack psdocker stack rmdocker stack servicesdocker startdocker statsdocker stopdocker swarmdocker swarm cadocker swarm initdocker swarm joindocker swarm join-tokendocker swarm leavedocker swarm unlockdocker swarm unlock-keydocker swarm updatedocker systemdocker system dfdocker system eventsdocker system infodocker system prunedocker tagdocker topdocker unpausedocker updatedocker versiondocker volumedocker volume createdocker volume inspectdocker volume lsdocker volume prunedocker volume rmdocker waitUse the Docker command line (Engine)Engine: ExtendAccess authorization plugin (Engine)Docker log driver pluginsDocker network driver plugins (Engine)Extending Engine with pluginsManaged plugin system (Engine)Plugin configuration (Engine)Plugins API (Engine)Volume plugins (Engine)Engine: SecurityAppArmor 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 EngineUse trusted imagesUsing certificates for repository client verification (Engine)Engine: TutorialsEngine tutorialsNetwork containers (Engine)Get StartedPart 1: OrientationPart 2: ContainersPart 3: ServicesPart 4: SwarmsPart 5: StacksPart 6: Deploy your appMachineAmazon Web Services (Machine)Digital Ocean (Machine)docker-machine activedocker-machine configdocker-machine createdocker-machine envdocker-machine helpdocker-machine inspectdocker-machine ipdocker-machine killdocker-machine lsdocker-machine provisiondocker-machine regenerate-certsdocker-machine restartdocker-machine rmdocker-machine scpdocker-machine sshdocker-machine startdocker-machine statusdocker-machine stopdocker-machine upgradedocker-machine urlDriver 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 MachineMachineMachine CLI overviewMachine command-line completionMachine concepts and helpMachine overviewMicrosoft Azure (Machine)Microsoft Hyper-V (Machine)Migrate from Boot2Docker to MachineOpenStack (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)NotaryClient configuration (Notary)Common Server and signer configurations (Notary)Getting started with NotaryNotary changelogNotary configuration filesRunning a Notary serviceServer 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
上一篇:下一篇: