官术网_书友最值得收藏!

Creating and inspecting a network

Let's create a network. We are going to call our network myNetwork. Execute the following command from the shell or command line:

$ docker network create myNetwork  

This is the simplest form of the command, and yet it will probably be used the most often. It takes a default driver (we haven't used any option to specify a driver, we will just use the default one, which is bridge). As the output, Docker will print out the identifier of the newly created network:

You will later use this identifier to refer to this network when connecting containers to it or inspecting the network's properties. The last parameter of the command is the network's name, which is a lot more convenient and easier to remember than the ID. The network name in our case is myNetwork. The docker network create command takes more parameters, as shown in the following table:

Option

Description

-d, -driver="bridge"

Driver to manage the network

-aux-address=map[]

Auxiliary IPv4 or IPv6 addresses used by network driver

-gateway=[]

IPv4 or IPv6 gateway for the master subnet

-ip-range=[]

Allocate container IP from a sub-range

-ipam-driver=default

IP address management driver

-o, -opt=map[]

Set driver's specific options

-subnet=[]

Subnet in CIDR format that represents a network segment

One of the most important parameters is the -d (--driver) option, with the default value bridge. Drivers let you specify the network type. As you remember, Docker has a couple of drivers available by default: host, bridge, and none.

After creating a network, we can inspect its properties using the docker network inspect command. Execute the following from the shell or command line:

$ docker network inspect myNetwork 

In response, you will get a lot of detailed information about your network. As you can see in the screenshot, our newly created network uses the bridge driver, even if we haven't explicitly asked for it:

As you can see, the container list is empty, and the reason why is that we haven't connected any container to this network yet. Let's do it now.

主站蜘蛛池模板: 会同县| 抚顺市| 屯留县| 鹤峰县| 肥西县| 永登县| 油尖旺区| 长治县| 通海县| 什邡市| 海安县| 丹寨县| 玉山县| 伊金霍洛旗| 云浮市| 黄浦区| 台山市| 侯马市| 新丰县| 类乌齐县| 昌图县| 郎溪县| 富源县| 隆化县| 福鼎市| 临沭县| 桂阳县| 桐柏县| 高陵县| 天祝| 延庆县| 肥东县| 峡江县| 渑池县| 上犹县| 花莲县| 太保市| 凯里市| 梁平县| 古丈县| 获嘉县|