如何在docker堆栈部署中禁用网络生成

时间:2017-09-29 08:54:05

标签: docker docker-compose docker-stack

我正在通过以下方式将撰写文件部署到UCP

docker stack deploy -c docker-compose.yml custom-stack-name

最后,我想将多个撰写文件(每个撰写文件描述单独的微服务的设置)部署到一个docker网络上,例如appsnetwork

version: "3"
services:

  service1:
    image: docker/service1
    networks:
      - appsnetwork

  customservice2:
    image: myprivaterepo/imageforcustomservice2
    networks:
      - appsnetwork

networks:
  appsnetwork:

docker stack deploy命令会自动创建一个生成名称的新网络,如下所示:custom-stack-name_appsnetwork

我有什么选择?

1 个答案:

答案 0 :(得分:1)

首先尝试自己创建网络

docker network create --driver=overlay --scope=swarm appsnetwork

之后,在撰写

中使网络成为外部网络
version: "3"
services:
  service1:
    image: nginx
    networks:
      - appsnetwork

networks:
  appsnetwork:
    external: true

之后运行两个堆栈副本

docker stack deploy --compose-file docker-compose.yml stack1
docker stack deploy --compose-file docker-compose.yml stack2

Docker检查两个节目在同一网络中的IP

$ docker inspect 369b610110a9
  ...
            "Networks": {
                "appsnetwork": {
                    "IPAMConfig": {
                        "IPv4Address": "10.0.1.5"
                    },
                    "Links": null,
                    "Aliases": [
                        "369b610110a9"
                    ],

$ docker inspect e8b8cc1a81ed

            "Networks": {
                "appsnetwork": {
                    "IPAMConfig": {
                        "IPv4Address": "10.0.1.3"
                    },
                    "Links": null,
                    "Aliases": [
                        "e8b8cc1a81ed"
                    ],