gpt4 book ai didi

docker - 如何将 `docker network create` CLI选项转换为可用于 `docker stack deploy`的撰写格式?

转载 作者:行者123 更新时间:2023-12-02 18:15:55 26 4
gpt4 key购买 nike

用例上下文:我需要通过docker run进行一些批处理,该批处理使用群体覆盖网络连接到服务。
我想使用docker stack deploy推出网络和服务设置;
单个容器任务假脱机直接通过REST API完成。

因此,我想用docker-compose.yml版本3+文件来表达以下shell命令。

$ docker network create \
--driver overlay \
--opt encrypted \
--internal \
--attachable \
--subnet 10.42.6.0/24 \
example_net

检查此网络可以很好地说明参数的解释方式。
$ docker network inspect example_net

[{
"Name": "example_net",
"Id": "lw689m2su19p5imljtlfsfsxy",
"Created": "0001-01-01T00:00:00Z",
"Scope": "swarm",
"Driver": "overlay",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "10.42.6.0/24",
"Gateway": "10.42.6.1"
}
]
},
"Internal": true,
"Attachable": true,
"Containers": null,
"Options": {
"com.docker.network.driver.overlay.vxlanid_list": "4098",
"encrypted": ""
},
"Labels": null
}]

将这些检查结果转换为我在 docker-compose.yml上的第一个片段:
version: "3.1"
networks:
example_net:
internal: true
driver_opts:
encrypted: ""
ipam:
config:
- subnet: 172.16.4.0/24

services:
db:
image: couchdb
networks:
- example_net
hostname: "{{.Service.Name}}-{{.Task.Slot}}-{{.Node.ID}}"

…接近的配置结果:
$ docker stack deploy -c ./docker-compose.yml test

Creating network test_example_net
Creating service test_db

$ docker network inspect example_net

[{
"Name": "test_example_net",
"Id": "j1ahedyfh05mpg5g52vrd9034",
"Created": "2017-04-21T21:00:55.656972306Z",
"Scope": "swarm",
"Driver": "overlay",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.16.4.0/24",
"Gateway": "172.16.4.1"
}
]
},
"Internal": true,
"Attachable": false,
"Containers": { ... },
"Options": {
"com.docker.network.driver.overlay.vxlanid_list": "4100",
"encrypted": ""
},
"Labels": {"com.docker.stack.namespace": "test"},
"Peers": [ ... ]
}]

问题:是否可以使用 "Attachable": true命令设置 docker stack deploy

最佳答案

"attachable property not supported in docker-compose v3 format"有一个github问题。

This was added in #30742. It will be in Compose file v3.2 format in the next release.



所以应该在Compose的1.12版本中,并且可能需要Docker的17+版本的 docker stack

关于docker - 如何将 `docker network create` CLI选项转换为可用于 `docker stack deploy`的撰写格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43553609/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com