首页 > 解决方案 > 在 docker swarm stack deploy 期间没有在工作节点上创建覆盖网络

问题描述

我有一个带有单一管理器和 2 个工作节点的覆盖网络(名称覆盖测试)的 Docker 群集群。工作节点之一仅包含数据库服务器容器。当我在集群上部署堆栈并且我的堆栈不包含在工作节点上部署数据库服务器服务的说明时,我遇到了在节点上没有创建网络的问题。我的任务是手动将数据库服务器容器连接到该网络。我看到解决这个问题的唯一方法是使这个节点与 db 服务器作为群管理器,但群管理器应该只是其他主机。

有其他解决方法的想法吗?提前致谢。

用于部署的 Docker-compose:

version: "3.5"

services:

  test-front:
    build: ./host-front/test-front
    image: test-front:alpine-3
    depends_on:
      - test-back
    networks:
      - test-multihost
    deploy:
      replicas: 1
      placement:
        constraints:
          - node.labels.nodename == front

  test-back:
    build: ./host-front/test-back
    image: test-back:openjdk8-alpine
    restart: always
    networks:
      - test-multihost
    depends_on:
      - test-db
    deploy:
      replicas: 1
      placement:
        constraints:
          - node.labels.nodename == front

  test-adapter:
    build: ./host-front/test-adapter
    image: test-adapter:openjdk8-alpine
    restart: always
    networks:
      - test-multihost
    depends_on:
      - test-core
    deploy:
      replicas: 1
      placement:
        constraints:
          - node.labels.nodename == front

  test-core:
    build: ./host-main/test-core
    image: test-core:openjdk8-alpine
    restart: always
    depends_on:
      - test-db
    networks:
      - test-multihost
    deploy:
      replicas: 1
      placement:
        constraints:
          - node.labels.nodename == main

  test-db:
    build: ./host-main/test-db
    image: test-db:openjdk8-alpine
    restart: always
    depends_on:
      - test-postgres
    networks:
      - test-multihost
    deploy:
      replicas: 1
      placement:
        constraints:
          - node.labels.nodename == main

  test-postgres:
    build: ./host-db/test-postgres
    image: test-postgres:postgres-12.1-alpine
    restart: always
    networks:
      - test-multihost
    deploy:
      replicas: 1
      placement:
        constraints:
          - node.labels.nodename == db

networks:
  test-multihost:
    external: true

我手动创建了覆盖网络: docker network create -d overlay --attachable test-multihost

标签: dockerdocker-swarmswarmdocker-swarm-mode

解决方案


推荐阅读