1

After enabling authentication in mongodb config file, I am getting below error when I start docker

$ docker service logs -f --tail 100 db_router1
db_router1.1.ryl8z6fakfkb@vazlab1    | {"t":{"$date":"2022-02-09T09:11:27.149Z"},"s":"I",  "c":"NETWORK",  "id":23175,   "ctx":"main","msg":"Command getaddrinfo failed","attr":{"host":"config1","error":"Temporary failure in name resolution"}}
db_router1.1.ryl8z6fakfkb@vazlab1    | {"t":{"$date":"2022-02-09T09:11:37.159Z"},"s":"I",  "c":"NETWORK",  "id":23175,   "ctx":"main","msg":"Command getaddrinfo failed","attr":{"host":"config2","error":"Temporary failure in name resolution"}}
db_router1.1.ryl8z6fakfkb@vazlab1    | {"t":{"$date":"2022-02-09T09:11:47.170Z"},"s":"I",  "c":"NETWORK",  "id":23175,   "ctx":"main","msg":"Command getaddrinfo failed","attr":{"host":"config3","error":"Temporary failure in name resolution"}}
db_router1.1.ryl8z6fakfkb@vazlab1    | {"t":{"$date":"2022-02-09T09:11:57.180Z"},"s":"I",  "c":"NETWORK",  "id":23175,   "ctx":"main","msg":"Command getaddrinfo failed","attr":{"host":"config","error":"Temporary failure in name resolution"}}

Please help me resolving the error

I am using below docker-compose.yml file to start the docker:

$ cat vaz_db.yaml
version: "3.8"


# Define general settings for mongo config server
x-mongo-default: &mongo-default
  user: vaz:vaz
  stop_grace_period: 60s
  image: vazlab1:5000/mongo-vaz:4.4.5
  environment:
# provide your credentials here
    - MONGO_INITDB_ROOT_USERNAME=root
    - MONGO_INITDB_ROOT_PASSWORD=root
  networks:
    - db_mongo

x-replica-settings: &replica-settings
    mode: replicated
    replicas: 1
    restart_policy:
      condition: any

# SWARM CONFIGS

x-cluster-configs: &cluster-configs
  configs:
    - source: cluster
      target: /app/cluster.conf

x-config-configs: &config-configs
  configs:
    - source: config
      target: /app/config.conf

x-router-configs: &router-configs
  configs:
    - source: router
      target: /app/router.conf

# RESOURCE CONSTRAINTS

x-config-resources: &config-resources
    <<: *replica-settings
    resources:
      limits:
        memory: 4G
      reservations:
        memory: 1G

x-cluster-resources: &cluster-resources
    <<: *replica-settings
    resources:
      limits:
        memory: 25G
      reservations:
        memory: 15G

x-router-resources: &router-resources
    <<: *replica-settings
    resources:
      limits:
        memory: 7G
      reservations:
        memory: 2G

# PLACEMENT CONSTRAINTS

x-vazlab1-placement: &vazlab1-placement
  placement:
    constraints:
      - "node.hostname==vazlab1"

x-vazlab2-placement: &vazlab2-placement
  placement:
    constraints:
      - "node.hostname==vazlab2"

# DEPLOY DEFINITIONS

x-config-vazlab1: &config-vazlab1
  command: mongod --auth --config /app/config.conf
  deploy:
    <<: *vazlab1-placement
    <<: *config-resources

x-config-vazlab2: &config-vazlab2
  command: mongod --auth --config /app/config.conf
  deploy:
    <<: *vazlab2-placement
    <<: *config-resources

x-cluster-vazlab1: &cluster-vazlab1
  deploy:
    <<: *vazlab1-placement
    <<: *cluster-resources

x-cluster-vazlab2: &cluster-vazlab2
  deploy:
    <<: *vazlab2-placement
    <<: *cluster-resources

x-router-vazlab1: &router-vazlab1
  deploy:
    <<: *vazlab1-placement
    <<: *router-resources

x-router-vazlab2: &router-vazlab2
  deploy:
    <<: *vazlab2-placement
    <<: *router-resources

# SERVICES START HERE

services:
  config1:
    hostname: config1
    <<: *mongo-default
    <<: *config-configs
    <<: *config-vazlab1
    volumes:
      - type: bind
        source: "/db/config1"
        target: /data
      - "/logs/config1:/logs"
      - "/etc/passwd:/etc/passwd:ro"
    ports:
      - "28110:28110"

  config2:
    hostname: config2
    <<: *mongo-default
    <<: *config-configs
    <<: *config-vazlab2
    volumes:
      - type: bind
        source: "/db/config2"
        target: /data
      - "/logs/config2:/logs"
      - "/etc/passwd:/etc/passwd:ro"
    ports:
      - "28111:28110"

  config3:
    hostname: config3
    <<: *mongo-default
    <<: *config-configs
    <<: *config-vazlab1
    volumes:
      - type: bind
        source: "/db/config3"
        target: /data
      - "/logs/config3:/logs"
      - "/etc/passwd:/etc/passwd:ro"
    ports:
      - "28112:28110"

  c1n1:
    hostname: c1n1
    <<: *mongo-default
    <<: *cluster-configs
    <<: *cluster-vazlab1
    volumes:
      - type: bind
        source: "/db/c1n1"
        target: /data
      - "/logs/c1n1:/logs"
      - "/etc/passwd:/etc/passwd:ro"
    ports:
      - "28001:28001"
    command: mongod --auth --config /app/cluster.conf --logpath /logs/c1n1.log --replSet c1 --port 28001

  c1n2:
    hostname: c1n2
    <<: *mongo-default
    <<: *cluster-configs
    <<: *cluster-vazlab2
    volumes:
      - type: bind
        source: "/db/c1n2"
        target: /data
      - "/logs/c1n2:/logs"
      - "/etc/passwd:/etc/passwd:ro"
#    ports:
#      - "28001:28001"
    command: mongod --auth --config /app/cluster.conf --logpath /logs/c1n2.log --replSet c1 --port 28001

  c1n3:
    hostname: c1n3
    <<: *mongo-default
    <<: *cluster-configs
#    <<: *cluster-vazlab2
    volumes:
      - type: bind
        source: "/db/c1n3"
        target: /data
      - "/logs/c1n3:/logs"
      - "/etc/passwd:/etc/passwd:ro"
 #   ports:
 #     - "28001:28001"
    command: mongod --auth --config /app/cluster.conf --logpath /logs/c1n3.log --replSet c1 --port 28001

  c2n1:
    hostname: c2n1
    <<: *mongo-default
    <<: *cluster-configs
    <<: *cluster-vazlab2
    volumes:
      - type: bind
        source: "/db/c2n1"
        target: /data
      - "/logs/c2n1:/logs"
      - "/etc/passwd:/etc/passwd:ro"
    ports:
      - "28002:28002"
    command: mongod --auth --config /app/cluster.conf --logpath /logs/c2n1.log --replSet c2 --port 28002

  c2n2:
    hostname: c2n2
    <<: *mongo-default
    <<: *cluster-configs
    <<: *cluster-vazlab1
    volumes:
      - type: bind
        source: "/db/c2n2"
        target: /data
      - "/logs/c2n2:/logs"
      - "/etc/passwd:/etc/passwd:ro"
#    ports:
#      - "28002:28002"
    command: mongod --auth --config /app/cluster.conf --logpath /logs/c2n2.log --replSet c2 --port 28002

  c2n3:
    hostname: c2n3
    <<: *mongo-default
    <<: *cluster-configs
#    <<: *cluster-vazlab1
    volumes:
      - type: bind
        source: "/db/c2n3"
        target: /data
      - "/logs/c2n3:/logs"
      - "/etc/passwd:/etc/passwd:ro"
#    ports:
#      - "28002:28002"
    command: mongod --auth --config /app/cluster.conf --logpath /logs/c2n3.log --replSet c2 --port 28002

  c3n1:
    hostname: c3n1
    <<: *mongo-default
    <<: *cluster-configs
    <<: *cluster-vazlab1
    volumes:
      - type: bind
        source: "/db/c3n1"
        target: /data
      - "/logs/c3n1:/logs"
      - "/etc/passwd:/etc/passwd:ro"
    ports:
      - "28003:28003"
    command: mongod --auth --config /app/cluster.conf --logpath /logs/c3n1.log --replSet c3 --port 28003

  c3n2:
    hostname: c3n2
    <<: *mongo-default
    <<: *cluster-configs
    <<: *cluster-vazlab2
    volumes:
      - type: bind
        source: "/db/c3n2"
        target: /data
      - "/logs/c3n2:/logs"
      - "/etc/passwd:/etc/passwd:ro"
#    ports:
#      - "28003:28003"
    command: mongod --auth --config /app/cluster.conf --logpath /logs/c3n2.log --replSet c3 --port 28003

  c3n3:
    hostname: c3n3
    <<: *mongo-default
    <<: *cluster-configs
#    <<: *cluster-vazlab2
    volumes:
      - type: bind
        source: "/db/c3n3"
        target: /data
      - "/logs/c3n3:/logs"
      - "/etc/passwd:/etc/passwd:ro"
#    ports:
#      - "28003:28003"
    command: mongod --auth --config /app/cluster.conf --logpath /logs/c3n3.log --replSet c3 --port 28003

  c4n1:
    hostname: c4n1
    <<: *mongo-default
    <<: *cluster-configs
    <<: *cluster-vazlab2
    volumes:
      - type: bind
        source: "/db/c4n1"
        target: /data
      - "/logs/c4n1:/logs"
      - "/etc/passwd:/etc/passwd:ro"
    ports:
      - "28004:28004"
    command: mongod --auth --config /app/cluster.conf --logpath /logs/c4n1.log --replSet c4 --port 28004

  c4n2:
    hostname: c4n2
    <<: *mongo-default
    <<: *cluster-configs
    <<: *cluster-vazlab1
    volumes:
      - type: bind
        source: "/db/c4n2"
        target: /data
      - "/logs/c4n2:/logs"
      - "/etc/passwd:/etc/passwd:ro"
#    ports:
#      - "28004:28004"
    command: mongod --auth --config /app/cluster.conf --logpath /logs/c4n2.log --replSet c4 --port 28004

  c4n3:
    hostname: c4n3
    <<: *mongo-default
    <<: *cluster-configs
#    <<: *cluster-vazlab1
    volumes:
      - type: bind
        source: "/db/c4n3"
        target: /data
      - "/logs/c4n3:/logs"
      - "/etc/passwd:/etc/passwd:ro"
#    ports:
#      - "28004:28004"
    command: mongod --auth --config /app/cluster.conf --logpath /logs/c4n3.log --replSet c4 --port 28004

  c5n1:
    hostname: c5n1
    <<: *mongo-default
    <<: *cluster-configs
    <<: *cluster-vazlab1
    volumes:
      - type: bind
        source: "/db/c5n1"
        target: /data
      - "/logs/c5n1:/logs"
      - "/etc/passwd:/etc/passwd:ro"
    ports:
      - "28005:28005"
    command: mongod --auth --config /app/cluster.conf --logpath /logs/c5n1.log --replSet c5 --port 28005

  c5n2:
    hostname: c5n2
    <<: *mongo-default
    <<: *cluster-configs
    <<: *cluster-vazlab2
    volumes:
      - type: bind
        source: "/db/c5n2"
        target: /data
      - "/logs/c5n2:/logs"
      - "/etc/passwd:/etc/passwd:ro"
#    ports:
#      - "28005:28005"
    command: mongod --auth --config /app/cluster.conf --logpath /logs/c5n2.log --replSet c5 --port 28005

  c5n3:
    hostname: c5n3
    <<: *mongo-default
    <<: *cluster-configs
#    <<: *cluster-vazlab2
    volumes:
      - type: bind
        source: "/db/c5n3"
        target: /data
      - "/logs/c5n3:/logs"
      - "/etc/passwd:/etc/passwd:ro"
#    ports:
#      - "28005:28005"
    command: mongod --auth --config /app/cluster.conf --logpath /logs/c5n3.log --replSet c5 --port 28005

  c6n1:
    hostname: c6n1
    <<: *mongo-default
    <<: *cluster-configs
    <<: *cluster-vazlab2
    volumes:
      - type: bind
        source: "/db/c6n1"
        target: /data
      - "/logs/c6n1:/logs"
      - "/etc/passwd:/etc/passwd:ro"
    ports:
      - "28006:28006"
    command: mongod --auth --config /app/cluster.conf --logpath /logs/c6n1.log --replSet c6 --port 28006

  c6n2:
    hostname: c6n2
    <<: *mongo-default
    <<: *cluster-configs
    <<: *cluster-vazlab1
    volumes:
      - type: bind
        source: "/db/c6n2"
        target: /data
      - "/logs/c6n2:/logs"
      - "/etc/passwd:/etc/passwd:ro"
#    ports:
#      - "28006:28006"
    command: mongod --auth --config /app/cluster.conf --logpath /logs/c6n2.log --replSet c6 --port 28006

  c6n3:
    hostname: c6n3
    <<: *mongo-default
    <<: *cluster-configs
#    <<: *cluster-vazlab1
    volumes:
      - type: bind
        source: "/db/c6n3"
        target: /data
      - "/logs/c6n3:/logs"
      - "/etc/passwd:/etc/passwd:ro"
#    ports:
#      - "28006:28006"
    command: mongod --auth --config /app/cluster.conf --logpath /logs/c6n3.log --replSet c6 --port 28006

  c7n1:
    hostname: c7n1
    <<: *mongo-default
    <<: *cluster-configs
    <<: *cluster-vazlab1
    volumes:
      - type: bind
        source: "/db/c7n1"
        target: /data
      - "/logs/c7n1:/logs"
      - "/etc/passwd:/etc/passwd:ro"
    ports:
      - "28007:28007"
    command: mongod --auth --config /app/cluster.conf --logpath /logs/c7n1.log --replSet c7 --port 28007

  c7n2:
    hostname: c7n2
    <<: *mongo-default
    <<: *cluster-configs
    <<: *cluster-vazlab2
    volumes:
      - type: bind
        source: "/db/c7n2"
        target: /data
      - "/logs/c7n2:/logs"
      - "/etc/passwd:/etc/passwd:ro"
#    ports:
#      - "28007:28007"
    command: mongod --auth --config /app/cluster.conf --logpath /logs/c7n2.log --replSet c7 --port 28007

  c7n3:
    hostname: c7n3
    <<: *mongo-default
    <<: *cluster-configs
#    <<: *cluster-vazlab2
    volumes:
      - type: bind
        source: "/db/c7n3"
        target: /data
      - "/logs/c7n3:/logs"
      - "/etc/passwd:/etc/passwd:ro"
#    ports:
#      - "28007:28007"
    command: mongod --auth --config /app/cluster.conf --logpath /logs/c7n3.log --replSet c7 --port 28007

  router1:
    hostname: router1
    <<: *mongo-default
    <<: *router-configs
    <<: *router-vazlab1
    volumes:
      - "/logs/router:/logs"
      - "/etc/passwd:/etc/passwd:ro"
    networks:
      - db_mongo
      - db_mongos
    ports:
      - "28100:28100"
    command: mongos --config /app/router.conf --port 28100

  router2:
    hostname: router2
    <<: *mongo-default
    <<: *router-configs
    <<: *router-vazlab2
    volumes:
      - "/logs/router:/logs"
      - "/etc/passwd:/etc/passwd:ro"
    networks:
      - db_mongo
      - db_mongos
    ports:
      - "28101:28101"
    command: mongos --config /app/router.conf --port 28101

configs:
  cluster:
    file: /app/docker-configs/stack/db/cluster.conf
  config:
    file: /app/docker-configs/stack/db/config.conf
  router:
    file: /app/docker-configs/stack/db/router.conf

networks:
  db_mongo:
    external: true
    name: db_mongo
  db_mongos:
    external: true
    name: db_mongos

Before this issue, I was using mongodb without authentication and it was working fine. But when I enable authentication in mongodb config file and restarted docker then I am getting the above error which I have posted.

Please help me in resolving the issue

  • That `docker-compose.yml` file seems extremely complicated. Can you reduce it to a [mcve], perhaps with only 2 services and no YAML references? It's really hard to tell which service is producing the error or what it might be connecting to. – David Maze Feb 22 '22 at 11:11
  • One possibility is that the `<<:` merge keys are getting merged, and Compose is only keeping one of them (probably the last one), which means the `networks:` settings aren't getting applied; also see [Error Map Keys Must be unique while using YAML extension field in docker compose for django application](https://stackoverflow.com/questions/71192632/error-map-keys-must-be-unique-while-using-yaml-extension-field-in-docker-compose). – David Maze Feb 22 '22 at 11:18

0 Answers0