Mongodb docker is not working

Hi, I am completely new to MongoDB, I was working on the setup of an open-source notification system called NOVU, and I was deploying with docker,

this is the docker-compose file

version: '3'
services:
  redis:
    image: 'redis:alpine'
    container_name: redis
    logging:
      driver: 'none'
  mongodb:
    image: mongo
    container_name: mongodb
    logging:
      driver: 'none'
    environment:
      - PUID=1000
      - PGID=1000
    volumes:
      - mongodb:/data/db
    ports:
      - 27017:27017
    restart: unless-stopped
  api:
    image: 'ghcr.io/novuhq/novu/api:0.11.0'
    depends_on:
      - mongodb
      - redis
    container_name: api
    environment:
      NODE_ENV: ${NODE_ENV}
      API_ROOT_URL: ${API_ROOT_URL}
      DISABLE_USER_REGISTRATION: ${DISABLE_USER_REGISTRATION}
      PORT: ${API_PORT}
      FRONT_BASE_URL: ${FRONT_BASE_URL}
      MONGO_URL: ${MONGO_URL}
      REDIS_HOST: ${REDIS_HOST}
      REDIS_PORT: ${REDIS_PORT}
      REDIS_DB_INDEX: 2
      REDIS_CACHE_SERVICE_HOST: ${REDIS_CACHE_SERVICE_HOST}
      REDIS_CACHE_SERVICE_PORT: ${REDIS_CACHE_SERVICE_PORT}
      S3_LOCAL_STACK: ${S3_LOCAL_STACK}
      S3_BUCKET_NAME: ${S3_BUCKET_NAME}
      S3_REGION: ${S3_REGION}
      AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
      AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
      JWT_SECRET: ${JWT_SECRET}
      STORE_ENCRYPTION_KEY: ${STORE_ENCRYPTION_KEY}
      SENTRY_DSN: ${SENTRY_DSN}
      NEW_RELIC_APP_NAME: ${NEW_RELIC_APP_NAME}
      NEW_RELIC_LICENSE_KEY: ${NEW_RELIC_LICENSE_KEY}
    ports:
      - '3000:3000'
  ws:
    image: 'ghcr.io/novuhq/novu/ws:0.11.0'
    depends_on:
      - mongodb
      - redis
    container_name: ws
    environment:
      PORT: ${WS_PORT}
      NODE_ENV: ${NODE_ENV}
      MONGO_URL: ${MONGO_URL}
      REDIS_HOST: ${REDIS_HOST}
      REDIS_PORT: ${REDIS_PORT}
      JWT_SECRET: ${JWT_SECRET}
    ports:
      - '3002:3002'
  web:
    image: 'ghcr.io/novuhq/novu/web:0.11.0'
    depends_on:
      - api
    container_name: web
    environment:
      REACT_APP_API_URL: ${API_ROOT_URL}
      REACT_APP_ENVIRONMENT: ${NODE_ENV}
      REACT_APP_WIDGET_EMBED_PATH: ${WIDGET_EMBED_PATH}
      REACT_APP_DOCKER_HOSTED_ENV: 'true'
    ports:
      - 4200:4200
  widget:
    image: 'ghcr.io/novuhq/novu/widget:0.11.0'
    depends_on:
      - api
      - web
    container_name: widget
    environment:
      REACT_APP_API_URL: ${API_ROOT_URL}
      REACT_APP_WS_URL: ${REACT_APP_WS_URL}
      REACT_APP_ENVIRONMENT: ${NODE_ENV}
    ports:
      - 4500:4500
  embed:
    depends_on:
      - widget
    image: 'ghcr.io/novuhq/novu/embed:0.11.0'
    container_name: embed
    environment:
      WIDGET_URL: ${WIDGET_URL}
    ports:
      - 4701:4701
volumes:
  mongodb: ~

and this is the error


ws         | [Nest] 272  - 04/06/2023, 4:46:43 AM     LOG [NestFactory] Starting Nest application...
ws         | [Nest] 272  - 04/06/2023, 4:46:43 AM     LOG [InstanceLoader] JwtModule dependencies initialized +1ms
ws         | [Nest] 272  - 04/06/2023, 4:46:43 AM     LOG [InstanceLoader] AppModule dependencies initialized +0ms
ws         | [Nest] 272  - 04/06/2023, 4:46:43 AM     LOG [InstanceLoader] LoggerModule dependencies initialized +1ms
ws         | [Nest] 272  - 04/06/2023, 4:46:43 AM     LOG [InstanceLoader] TerminusModule dependencies initialized +0ms
ws         | [Nest] 272  - 04/06/2023, 4:46:43 AM     LOG [InstanceLoader] HealthModule dependencies initialized +0ms
ws         | [Nest] 272  - 04/06/2023, 4:46:43 AM     LOG [InstanceLoader] SocketModule dependencies initialized +0ms
ws         | [Nest] 272  - 04/06/2023, 4:46:43 AM   ERROR [ExceptionHandler] getaddrinfo EAI_AGAIN mongodb
ws         | MongooseServerSelectionError: getaddrinfo EAI_AGAIN mongodb
ws         |     at NativeConnection.Connection.openUri (/usr/src/app/node_modules/.pnpm/mongoose@6.10.1/node_modules/mongoose/lib/connection.js:825:32)
ws         |     at /usr/src/app/node_modules/.pnpm/mongoose@6.10.1/node_modules/mongoose/lib/index.js:414:10
ws         |     at /usr/src/app/node_modules/.pnpm/mongoose@6.10.1/node_modules/mongoose/lib/helpers/promiseOrCallback.js:41:5
ws         |     at new Promise (<anonymous>)
ws         |     at promiseOrCallback (/usr/src/app/node_modules/.pnpm/mongoose@6.10.1/node_modules/mongoose/lib/helpers/promiseOrCallback.js:40:10)
ws         |     at Mongoose._promiseOrCallback (/usr/src/app/node_modules/.pnpm/mongoose@6.10.1/node_modules/mongoose/lib/index.js:1288:10)
ws         |     at Mongoose.connect (/usr/src/app/node_modules/.pnpm/mongoose@6.10.1/node_modules/mongoose/lib/index.js:413:20)
ws         |     at DalService.<anonymous> (/usr/src/app/libs/dal/dist/dal.service.js:21:45)
ws         |     at Generator.next (<anonymous>)
ws         |     at /usr/src/app/libs/dal/dist/dal.service.js:8:71
ws         |     at new Promise (<anonymous>)
ws         |     at __awaiter (/usr/src/app/libs/dal/dist/dal.service.js:4:12)
ws         |     at DalService.connect (/usr/src/app/libs/dal/dist/dal.service.js:16:16)
ws         |     at /usr/src/app/apps/ws/src/shared/shared.module.ts:44:24
ws         |     at Generator.next (<anonymous>)
ws         |     at /usr/src/app/apps/ws/dist/src/shared/shared.module.js:14:71

Please note the Error message line
[Nest] 344 - 04/06/2023, 4:50:47 AM ERROR [ExceptionHandler] getaddrinfo EAI_AGAIN mongodb
any ideas?

Hi :wave: @Taha_Babi,

The error message implies that there is a problem resolving the hostname of your MongoDB server. The error code EAI_AGAIN indicates that the DNS lookup failed.

Can you please confirm if the MongoDB container is running? It appears that the container is not running, could you check the logs for any error messages related to the MongoDB container?

Best,
Kushagra

1 Like