【问题标题】:How do I translate the `docker network create` CLI options into compose format for `docker stack deploy` use?如何将 `docker network create` CLI 选项转换为 `docker stack deploy` 使用的组合格式?
【发布时间】:2017-04-21 23:48:21
【问题描述】:

用例上下文:我需要通过docker run 进行一些批处理,该docker run 使用swarm 覆盖网络连接到服务。 我想使用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": [ ... ]
}]

问题:有没有办法通过docker stack deploy 命令设置"Attachable": true

【问题讨论】:

    标签: docker docker-compose docker-swarm docker-networking


    【解决方案1】:

    "attachable property not supported in docker-compose v3 format" 存在 github 问题。

    这是在#30742 中添加的。它将在下一个版本中采用 Compose 文件 v3.2 格式。

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

    【讨论】:

      猜你喜欢
      • 2022-06-29
      • 2022-10-13
      • 2020-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-10
      • 1970-01-01
      相关资源
      最近更新 更多