无法在Docker管理器中连接或发现REDIS

时间:2019-06-28 12:24:38

标签: node.js docker redis docker-swarm docker-swarm-mode

我有2台计算机,其中一台初始化为管理员,其他一台作为工人加入。我有一个nodejs应用程序和redis,redis在管理器节点中。

当我尝试扩展nodejs应用程序服务时,Manager节点中的副本可以发现Redis,但worker节点中的容器找不到

我用IP替换了主机名“ hp-redis”,但我不想在生产环境中这样做

services:
  api:
    image: 'xxxx'
    ports:
      - '3000:3000'
    volumes:
      - type: volume
        source: hp-api-dev
        target: /usr/src/app/
      - type: volume
        source: logs
        target: /usr/src/app/logs/
      - type: bind
        source: /var/www/xxxx/
        target: /uploads
      - type: bind
        source: /etc/localtime
        target: /etc/localtime
        read_only: true
    deploy:
      replicas: 1
      restart_policy:
        max_attempts: 3
        condition: on-failure
      update_config:
        parallelism: 1
        delay: 10s
    networks:
      - webnetwork
    depends_on:
      - hp-redis
  hp-redis:
    image: 'redis:4.0'
    deploy:
      mode: global
      restart_policy:
        condition: on-failure
      resources:
        limits:
          cpus: '0.1'
          memory: 100M
      placement:
        constraints:
          - 'node.role == manager'
    ports:
      - '6379:6379'
    expose:
      - "6379"
    volumes:
      - type: bind
        source: /Data/redis/
        target: /home/docker/data
        read_only: true
    networks:
      - webnetwork
networks:
  webnetwork:
    driver: overlay
volumes:
  hp-api-dev:
  logs:

0 个答案:

没有答案