Fixes issue #19089
Signed-off-by: Wen Cheng Ma <wenchma@cn.ibm.com>
| ... | ... |
@@ -34,8 +34,8 @@ import ( |
| 34 | 34 |
// DefaultSHMSize is the default size (64MB) of the SHM which will be mounted in the container |
| 35 | 35 |
const DefaultSHMSize int64 = 67108864 |
| 36 | 36 |
|
| 37 |
-// Container holds the fields specific to unixen implementations. See |
|
| 38 |
-// CommonContainer for standard fields common to all containers. |
|
| 37 |
+// Container holds the fields specific to unixen implementations. |
|
| 38 |
+// See CommonContainer for standard fields common to all containers. |
|
| 39 | 39 |
type Container struct {
|
| 40 | 40 |
CommonContainer |
| 41 | 41 |
|
| ... | ... |
@@ -194,6 +194,7 @@ func (container *Container) BuildEndpointInfo(n libnetwork.Network, ep libnetwor |
| 194 | 194 |
if _, ok := networkSettings.Networks[n.Name()]; !ok {
|
| 195 | 195 |
networkSettings.Networks[n.Name()] = new(network.EndpointSettings) |
| 196 | 196 |
} |
| 197 |
+ networkSettings.Networks[n.Name()].NetworkID = n.ID() |
|
| 197 | 198 |
networkSettings.Networks[n.Name()].EndpointID = ep.ID() |
| 198 | 199 |
|
| 199 | 200 |
iface := epInfo.Iface() |
| ... | ... |
@@ -702,7 +703,7 @@ func copyExistingContents(source, destination string) error {
|
| 702 | 702 |
return err |
| 703 | 703 |
} |
| 704 | 704 |
if len(srcList) == 0 {
|
| 705 |
- // If the source volume is empty copy files from the root into the volume |
|
| 705 |
+ // If the source volume is empty, copies files from the root into the volume |
|
| 706 | 706 |
if err := chrootarchive.CopyWithTar(source, destination); err != nil {
|
| 707 | 707 |
return err |
| 708 | 708 |
} |
| ... | ... |
@@ -116,6 +116,7 @@ This section lists each version from latest to oldest. Each listing includes a |
| 116 | 116 |
* `GET /info` now includes the number of containers running, stopped, and paused. |
| 117 | 117 |
* `POST /networks/create` now supports restricting external access to the network by setting the `internal` field. |
| 118 | 118 |
* `POST /networks/(id)/disconnect` now includes a `Force` option to forcefully disconnect a container from network |
| 119 |
+* `GET /containers/(id)/json` now returns the `NetworkID` of containers. |
|
| 119 | 120 |
|
| 120 | 121 |
### v1.21 API changes |
| 121 | 122 |
|
| ... | ... |
@@ -61,6 +61,7 @@ List containers |
| 61 | 61 |
"NetworkSettings": {
|
| 62 | 62 |
"Networks": {
|
| 63 | 63 |
"bridge": {
|
| 64 |
+ "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", |
|
| 64 | 65 |
"EndpointID": "2cdc4edb1ded3631c81f57966563e5c8525b81121bb3706a9a9a3ae102711f3f", |
| 65 | 66 |
"Gateway": "172.17.0.1", |
| 66 | 67 |
"IPAddress": "172.17.0.2", |
| ... | ... |
@@ -88,6 +89,7 @@ List containers |
| 88 | 88 |
"NetworkSettings": {
|
| 89 | 89 |
"Networks": {
|
| 90 | 90 |
"bridge": {
|
| 91 |
+ "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", |
|
| 91 | 92 |
"EndpointID": "88eaed7b37b38c2a3f0c4bc796494fdf51b270c2d22656412a2ca5d559a64d7a", |
| 92 | 93 |
"Gateway": "172.17.0.1", |
| 93 | 94 |
"IPAddress": "172.17.0.8", |
| ... | ... |
@@ -116,6 +118,7 @@ List containers |
| 116 | 116 |
"NetworkSettings": {
|
| 117 | 117 |
"Networks": {
|
| 118 | 118 |
"bridge": {
|
| 119 |
+ "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", |
|
| 119 | 120 |
"EndpointID": "8b27c041c30326d59cd6e6f510d4f8d1d570a228466f956edf7815508f78e30d", |
| 120 | 121 |
"Gateway": "172.17.0.1", |
| 121 | 122 |
"IPAddress": "172.17.0.6", |
| ... | ... |
@@ -144,6 +147,7 @@ List containers |
| 144 | 144 |
"NetworkSettings": {
|
| 145 | 145 |
"Networks": {
|
| 146 | 146 |
"bridge": {
|
| 147 |
+ "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", |
|
| 147 | 148 |
"EndpointID": "d91c7b2f0644403d7ef3095985ea0e2370325cd2332ff3a3225c4247328e66e9", |
| 148 | 149 |
"Gateway": "172.17.0.1", |
| 149 | 150 |
"IPAddress": "172.17.0.5", |
| ... | ... |
@@ -545,14 +549,15 @@ Return low-level information on the container `id` |
| 545 | 545 |
"MacAddress": "", |
| 546 | 546 |
"Networks": {
|
| 547 | 547 |
"bridge": {
|
| 548 |
- "EndpointID": "", |
|
| 549 |
- "Gateway": "", |
|
| 550 |
- "IPAddress": "", |
|
| 551 |
- "IPPrefixLen": 0, |
|
| 548 |
+ "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", |
|
| 549 |
+ "EndpointID": "7587b82f0dada3656fda26588aee72630c6fab1536d36e394b2bfbcf898c971d", |
|
| 550 |
+ "Gateway": "172.17.0.1", |
|
| 551 |
+ "IPAddress": "172.17.0.2", |
|
| 552 |
+ "IPPrefixLen": 16, |
|
| 552 | 553 |
"IPv6Gateway": "", |
| 553 | 554 |
"GlobalIPv6Address": "", |
| 554 | 555 |
"GlobalIPv6PrefixLen": 0, |
| 555 |
- "MacAddress": "" |
|
| 556 |
+ "MacAddress": "02:42:ac:12:00:02" |
|
| 556 | 557 |
} |
| 557 | 558 |
} |
| 558 | 559 |
}, |
| ... | ... |
@@ -2687,14 +2692,15 @@ Return low-level information about the `exec` command `id`. |
| 2687 | 2687 |
"MacAddress": "", |
| 2688 | 2688 |
"Networks": {
|
| 2689 | 2689 |
"bridge": {
|
| 2690 |
- "EndpointID": "", |
|
| 2691 |
- "Gateway": "", |
|
| 2692 |
- "IPAddress": "", |
|
| 2693 |
- "IPPrefixLen": 0, |
|
| 2690 |
+ "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", |
|
| 2691 |
+ "EndpointID": "7587b82f0dada3656fda26588aee72630c6fab1536d36e394b2bfbcf898c971d", |
|
| 2692 |
+ "Gateway": "172.17.0.1", |
|
| 2693 |
+ "IPAddress": "172.17.0.2", |
|
| 2694 |
+ "IPPrefixLen": 16, |
|
| 2694 | 2695 |
"IPv6Gateway": "", |
| 2695 | 2696 |
"GlobalIPv6Address": "", |
| 2696 | 2697 |
"GlobalIPv6PrefixLen": 0, |
| 2697 |
- "MacAddress": "" |
|
| 2698 |
+ "MacAddress": "02:42:ac:12:00:02" |
|
| 2698 | 2699 |
} |
| 2699 | 2700 |
} |
| 2700 | 2701 |
}, |
| ... | ... |
@@ -174,7 +174,8 @@ Now, inspect the network resources used by `container3`. |
| 174 | 174 |
|
| 175 | 175 |
```bash |
| 176 | 176 |
$ docker inspect --format='{{json .NetworkSettings.Networks}}' container3
|
| 177 |
-{"isolated_nw":{"IPAMConfig":{"IPv4Address":"172.25.3.3"},"EndpointID":"dffc7ec2915af58cc827d995e6ebdc897342be0420123277103c40ae35579103","Gateway":"172.25.0.1","IPAddress":"172.25.3.3","IPPrefixLen":16,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"MacAddress":"02:42:ac:19:03:03"}}
|
|
| 177 |
+{"isolated_nw":{"IPAMConfig":{"IPv4Address":"172.25.3.3"},"NetworkID":"1196a4c5af43a21ae38ef34515b6af19236a3fc48122cf585e3f3054d509679b",
|
|
| 178 |
+"EndpointID":"dffc7ec2915af58cc827d995e6ebdc897342be0420123277103c40ae35579103","Gateway":"172.25.0.1","IPAddress":"172.25.3.3","IPPrefixLen":16,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"MacAddress":"02:42:ac:19:03:03"}} |
|
| 178 | 179 |
``` |
| 179 | 180 |
Repeat this command for `container2`. If you have Python installed, you can pretty print the output. |
| 180 | 181 |
|
| ... | ... |
@@ -182,6 +183,7 @@ Repeat this command for `container2`. If you have Python installed, you can pret |
| 182 | 182 |
$ docker inspect --format='{{json .NetworkSettings.Networks}}' container2 | python -m json.tool
|
| 183 | 183 |
{
|
| 184 | 184 |
"bridge": {
|
| 185 |
+ "NetworkID":"7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", |
|
| 185 | 186 |
"EndpointID": "0099f9efb5a3727f6a554f176b1e96fca34cae773da68b3b6a26d046c12cb365", |
| 186 | 187 |
"Gateway": "172.17.0.1", |
| 187 | 188 |
"GlobalIPv6Address": "", |
| ... | ... |
@@ -193,6 +195,7 @@ $ docker inspect --format='{{json .NetworkSettings.Networks}}' container2 | pyt
|
| 193 | 193 |
"MacAddress": "02:42:ac:11:00:03" |
| 194 | 194 |
}, |
| 195 | 195 |
"isolated_nw": {
|
| 196 |
+ "NetworkID":"1196a4c5af43a21ae38ef34515b6af19236a3fc48122cf585e3f3054d509679b", |
|
| 196 | 197 |
"EndpointID": "11cedac1810e864d6b1589d92da12af66203879ab89f4ccd8c8fdaa9b1c48b1d", |
| 197 | 198 |
"Gateway": "172.25.0.1", |
| 198 | 199 |
"GlobalIPv6Address": "", |
| ... | ... |
@@ -511,6 +514,7 @@ $ docker network disconnect isolated_nw container2 |
| 511 | 511 |
docker inspect --format='{{json .NetworkSettings.Networks}}' container2 | python -m json.tool
|
| 512 | 512 |
{
|
| 513 | 513 |
"bridge": {
|
| 514 |
+ "NetworkID":"7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", |
|
| 514 | 515 |
"EndpointID": "9e4575f7f61c0f9d69317b7a4b92eefc133347836dd83ef65deffa16b9985dc0", |
| 515 | 516 |
"Gateway": "172.17.0.1", |
| 516 | 517 |
"GlobalIPv6Address": "", |
| ... | ... |
@@ -189,7 +189,8 @@ If you inspect your `my-bridge-network` you'll see it has a container attached. |
| 189 | 189 |
You can also inspect your container to see where it is connected: |
| 190 | 190 |
|
| 191 | 191 |
$ docker inspect --format='{{json .NetworkSettings.Networks}}' db
|
| 192 |
- {"bridge":{"EndpointID":"508b170d56b2ac9e4ef86694b0a76a22dd3df1983404f7321da5649645bf7043","Gateway":"172.18.0.1","IPAddress":"172.18.0.2","IPPrefixLen":16,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"MacAddress":"02:42:ac:11:00:02"}}
|
|
| 192 |
+ {"my-bridge-network":{"NetworkID":"7d86d31b1478e7cca9ebed7e73aa0fdeec46c5ca29497431d3007d2d9e15ed99",
|
|
| 193 |
+ "EndpointID":"508b170d56b2ac9e4ef86694b0a76a22dd3df1983404f7321da5649645bf7043","Gateway":"172.18.0.1","IPAddress":"172.18.0.2","IPPrefixLen":16,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"MacAddress":"02:42:ac:11:00:02"}} |
|
| 193 | 194 |
|
| 194 | 195 |
Now, go ahead and start your by now familiar web application. This time leave off the `-P` flag and also don't specify a network. |
| 195 | 196 |
|
| ... | ... |
@@ -198,7 +199,8 @@ Now, go ahead and start your by now familiar web application. This time leave of |
| 198 | 198 |
Which network is your `web` application running under? Inspect the application and you'll find it is running in the default `bridge` network. |
| 199 | 199 |
|
| 200 | 200 |
$ docker inspect --format='{{json .NetworkSettings.Networks}}' web
|
| 201 |
- {"bridge":{"EndpointID":"508b170d56b2ac9e4ef86694b0a76a22dd3df1983404f7321da5649645bf7043","Gateway":"172.17.0.1","IPAddress":"172.17.0.2","IPPrefixLen":16,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"MacAddress":"02:42:ac:11:00:02"}}
|
|
| 201 |
+ {"bridge":{"NetworkID":"7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812",
|
|
| 202 |
+ "EndpointID":"508b170d56b2ac9e4ef86694b0a76a22dd3df1983404f7321da5649645bf7043","Gateway":"172.17.0.1","IPAddress":"172.17.0.2","IPPrefixLen":16,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"MacAddress":"02:42:ac:11:00:02"}} |
|
| 202 | 203 |
|
| 203 | 204 |
Then, get the IP address of your `web` |
| 204 | 205 |
|
| ... | ... |
@@ -388,3 +388,30 @@ func (s *DockerSuite) TestInspectHistory(c *check.C) {
|
| 388 | 388 |
c.Assert(err, check.IsNil) |
| 389 | 389 |
c.Assert(out, checker.Contains, "test comment") |
| 390 | 390 |
} |
| 391 |
+ |
|
| 392 |
+func (s *DockerSuite) TestInspectContainerNetworkDefault(c *check.C) {
|
|
| 393 |
+ testRequires(c, DaemonIsLinux) |
|
| 394 |
+ |
|
| 395 |
+ contName := "test1" |
|
| 396 |
+ dockerCmd(c, "run", "--name", contName, "-d", "busybox", "top") |
|
| 397 |
+ netOut, _ := dockerCmd(c, "network", "inspect", "--format='{{.ID}}'", "bridge")
|
|
| 398 |
+ out, err := inspectField(contName, "NetworkSettings.Networks") |
|
| 399 |
+ c.Assert(err, checker.IsNil) |
|
| 400 |
+ c.Assert(out, checker.Contains, "bridge") |
|
| 401 |
+ out, err = inspectField(contName, "NetworkSettings.Networks.bridge.NetworkID") |
|
| 402 |
+ c.Assert(err, checker.IsNil) |
|
| 403 |
+ c.Assert(strings.TrimSpace(out), checker.Equals, strings.TrimSpace(netOut)) |
|
| 404 |
+} |
|
| 405 |
+ |
|
| 406 |
+func (s *DockerSuite) TestInspectContainerNetworkCustom(c *check.C) {
|
|
| 407 |
+ testRequires(c, DaemonIsLinux) |
|
| 408 |
+ |
|
| 409 |
+ netOut, _ := dockerCmd(c, "network", "create", "net1") |
|
| 410 |
+ dockerCmd(c, "run", "--name=container1", "--net=net1", "-d", "busybox", "top") |
|
| 411 |
+ out, err := inspectField("container1", "NetworkSettings.Networks")
|
|
| 412 |
+ c.Assert(err, checker.IsNil) |
|
| 413 |
+ c.Assert(out, checker.Contains, "net1") |
|
| 414 |
+ out, err = inspectField("container1", "NetworkSettings.Networks.net1.NetworkID")
|
|
| 415 |
+ c.Assert(err, checker.IsNil) |
|
| 416 |
+ c.Assert(strings.TrimSpace(out), checker.Equals, strings.TrimSpace(netOut)) |
|
| 417 |
+} |
| ... | ... |
@@ -72,22 +72,36 @@ To get information on a container use its ID or instance name: |
| 72 | 72 |
"Image": "ded7cd95e059788f2586a51c275a4f151653779d6a7f4dad77c2bd34601d94e4", |
| 73 | 73 |
"NetworkSettings": {
|
| 74 | 74 |
"Bridge": "", |
| 75 |
- "EndpointID": "", |
|
| 76 |
- "Gateway": "", |
|
| 77 |
- "GlobalIPv6Address": "", |
|
| 78 |
- "GlobalIPv6PrefixLen": 0, |
|
| 75 |
+ "SandboxID": "6b4851d1903e16dd6a567bd526553a86664361f31036eaaa2f8454d6f4611f6f", |
|
| 79 | 76 |
"HairpinMode": false, |
| 80 |
- "IPAddress": "", |
|
| 81 |
- "IPPrefixLen": 0, |
|
| 82 |
- "IPv6Gateway": "", |
|
| 83 | 77 |
"LinkLocalIPv6Address": "", |
| 84 | 78 |
"LinkLocalIPv6PrefixLen": 0, |
| 85 |
- "MacAddress": "", |
|
| 86 |
- "NetworkID": "", |
|
| 87 |
- "Ports": null, |
|
| 88 |
- "SandboxKey": "", |
|
| 79 |
+ "Ports": {},
|
|
| 80 |
+ "SandboxKey": "/var/run/docker/netns/6b4851d1903e", |
|
| 89 | 81 |
"SecondaryIPAddresses": null, |
| 90 |
- "SecondaryIPv6Addresses": null |
|
| 82 |
+ "SecondaryIPv6Addresses": null, |
|
| 83 |
+ "EndpointID": "7587b82f0dada3656fda26588aee72630c6fab1536d36e394b2bfbcf898c971d", |
|
| 84 |
+ "Gateway": "172.17.0.1", |
|
| 85 |
+ "GlobalIPv6Address": "", |
|
| 86 |
+ "GlobalIPv6PrefixLen": 0, |
|
| 87 |
+ "IPAddress": "172.17.0.2", |
|
| 88 |
+ "IPPrefixLen": 16, |
|
| 89 |
+ "IPv6Gateway": "", |
|
| 90 |
+ "MacAddress": "02:42:ac:12:00:02", |
|
| 91 |
+ "Networks": {
|
|
| 92 |
+ "bridge": {
|
|
| 93 |
+ "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", |
|
| 94 |
+ "EndpointID": "7587b82f0dada3656fda26588aee72630c6fab1536d36e394b2bfbcf898c971d", |
|
| 95 |
+ "Gateway": "172.17.0.1", |
|
| 96 |
+ "IPAddress": "172.17.0.2", |
|
| 97 |
+ "IPPrefixLen": 16, |
|
| 98 |
+ "IPv6Gateway": "", |
|
| 99 |
+ "GlobalIPv6Address": "", |
|
| 100 |
+ "GlobalIPv6PrefixLen": 0, |
|
| 101 |
+ "MacAddress": "02:42:ac:12:00:02" |
|
| 102 |
+ } |
|
| 103 |
+ } |
|
| 104 |
+ |
|
| 91 | 105 |
}, |
| 92 | 106 |
"ResolvConfPath": "/var/lib/docker/containers/d2cc496561d6d520cbc0236b4ba88c362c446a7619992123f11c809cded25b47/resolv.conf", |
| 93 | 107 |
"HostnamePath": "/var/lib/docker/containers/d2cc496561d6d520cbc0236b4ba88c362c446a7619992123f11c809cded25b47/hostname", |