Мне нужно подключить контейнер, созданный с помощью Docker Engine API, к существующей сети.
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
2babcf993368 bridge bridge local
8a865b5fedae cron-container_my-net bridge local
94e1d6468f07 host host local
92f72e792ec8 none null local
Сеть, которую я хочу подключить к своему контейнеру, должна быть cron-container_my-net , и это мой .json для создания контейнера.
{
"Image": "my-job",
"Name": "my-container",
"HostConfig": {
"NetworkMode": "cron-container_my-net"
},
"NetworkDisable": "false"
}
Таким образом, если я проверю:
$ docker inspect my-container
[...]
"NetworkSettings": {
"Bridge": "",
"SandboxID": "130b79dca9cf45fed41e50da897e8d37a18160900a8390733300dc01f691ac94",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/130b79dca9cf",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"cron-container_my-net": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"387929d92ffc"
],
"NetworkID": "8a865b5fedaea1192ec0c6dcd742fc51af28001132c0ae375bdca018eb4706c9",
"EndpointID": "",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "",
"DriverOpts": null
}
}
}
Но если я проверяю контейнер, уже подключенный к сети, это результат:
$ docker inspect other-container
[...]
"NetworkSettings": {
"Bridge": "",
"SandboxID": "0d5e7e600a3ef46090675409a5eb444c1e31520e3c8c6908e6bda69ba9759335",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"3000/tcp": null
},
"SandboxKey": "/var/run/docker/netns/0d5e7e600a3e",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"cron-container_my-net": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"89c1aa28e3af",
"socket-io"
],
"NetworkID": "8a865b5fedaea1192ec0c6dcd742fc51af28001132c0ae375bdca018eb4706c9",
"EndpointID": "01f46a675125c2978de706a2c2ae46f942546028309e18c5561c91f3e7b147e4",
"Gateway": "172.18.0.1",
"IPAddress": "172.18.0.3",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:12:00:03",
"DriverOpts": null
}
}
}
Как можно подключить my-container?