1

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

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

最后,我想将多个 compose 文件(每个 compose 文件描述一个单独的微服务的设置)部署到一个 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

我有哪些选择?

4

1 回答 1

2

尝试先自己创建网络

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"
                    ],
于 2017-09-29T09:13:11.777 回答