2017-04-21 72 views
0

用例上下文:我需要通過docker run進行一些批處理,這些批處理通過使用羣集覆蓋網絡連接到服務。 我想用docker stack deploy推出網絡和服務設置; 單個容器任務後臺處理直接通過REST API完成。如何將`docker network create` CLI選項翻譯爲`docker stack deploy`的組合格式?

因此,我想根據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

回答