Docker mongo and mongo-express connection issue
Asked Answered
N

3

6

When I'm trying to connect to mongo-express I'm getting a connection issue, kind of error

version: "3"
services:
  mongodb:
    image: mongo
    ports:
      - "27017:27017"
    environment:
      - MONGO_INITDB_ROOT_USERNAME=anirban
      - MONGO_INITDB_ROOT_PASSWORD=mypass
  mongo-express:
    image: mongo-express
    ports: 
      - "8081:8081"
    restart: always
    environment:
      - ME_CONFIG_MONGODB_SERVER=mongodb
      - ME_CONFIG_MONGODB_ADMINUSERNAME=anirban
      - ME_CONFIG_MONGODB_ADMINPASSWORD=mypass

The above is my docker-compose.yaml

so after this, in my docker desktop > mongo-express process I'm getting this page, Running container

Then after 1 minute approx, I'm getting the localhost:8081 up and running in my browser,

2024-01-21 13:15:53 /docker-entrypoint.sh: line 15: mongo: Try again
2024-01-21 13:15:53 /docker-entrypoint.sh: line 15: /dev/tcp/mongo/27017: Invalid argument
2024-01-21 13:15:59 /docker-entrypoint.sh: line 15: mongo: Try again
2024-01-21 13:15:59 /docker-entrypoint.sh: line 15: /dev/tcp/mongo/27017: Invalid argument
2024-01-21 13:16:05 /docker-entrypoint.sh: line 15: mongo: Try again
2024-01-21 13:16:05 /docker-entrypoint.sh: line 15: /dev/tcp/mongo/27017: Invalid argument
2024-01-21 13:15:48 Waiting for mongo:27017...
2024-01-21 13:15:54 Sun Jan 21 07:45:54 UTC 2024 retrying to connect to mongo:27017 (2/10)
2024-01-21 13:16:00 Sun Jan 21 07:46:00 UTC 2024 retrying to connect to mongo:27017 (3/10)
2024-01-21 13:16:06 Sun Jan 21 07:46:06 UTC 2024 retrying to connect to mongo:27017 (4/10)
2024-01-21 13:16:11 /docker-entrypoint.sh: line 15: mongo: Try again
2024-01-21 13:16:11 /docker-entrypoint.sh: line 15: /dev/tcp/mongo/27017: Invalid argument
2024-01-21 13:16:12 Sun Jan 21 07:46:12 UTC 2024 retrying to connect to mongo:27017 (5/10)
2024-01-21 13:16:17 /docker-entrypoint.sh: line 15: mongo: Try again
2024-01-21 13:16:17 /docker-entrypoint.sh: line 15: /dev/tcp/mongo/27017: Invalid argument
2024-01-21 13:16:18 Sun Jan 21 07:46:18 UTC 2024 retrying to connect to mongo:27017 (6/10)
2024-01-21 13:16:23 /docker-entrypoint.sh: line 15: mongo: Try again
2024-01-21 13:16:23 /docker-entrypoint.sh: line 15: /dev/tcp/mongo/27017: Invalid argument
2024-01-21 13:16:24 Sun Jan 21 07:46:24 UTC 2024 retrying to connect to mongo:27017 (7/10)
2024-01-21 13:16:29 /docker-entrypoint.sh: line 15: mongo: Try again
2024-01-21 13:16:29 /docker-entrypoint.sh: line 15: /dev/tcp/mongo/27017: Invalid argument
2024-01-21 13:16:30 Sun Jan 21 07:46:30 UTC 2024 retrying to connect to mongo:27017 (8/10)
2024-01-21 13:16:35 /docker-entrypoint.sh: line 15: mongo: Try again
2024-01-21 13:16:35 /docker-entrypoint.sh: line 15: /dev/tcp/mongo/27017: Invalid argument
2024-01-21 13:16:36 Sun Jan 21 07:46:36 UTC 2024 retrying to connect to mongo:27017 (9/10)
2024-01-21 13:16:41 /docker-entrypoint.sh: line 15: mongo: Try again
2024-01-21 13:16:41 /docker-entrypoint.sh: line 15: /dev/tcp/mongo/27017: Invalid argument
2024-01-21 13:16:42 Sun Jan 21 07:46:42 UTC 2024 retrying to connect to mongo:27017 (10/10)
2024-01-21 13:16:47 /docker-entrypoint.sh: line 15: mongo: Try again
2024-01-21 13:16:47 /docker-entrypoint.sh: line 15: /dev/tcp/mongo/27017: Invalid argument
2024-01-21 13:16:48 No custom config.js found, loading config.default.js
2024-01-21 13:16:48 Welcome to mongo-express 1.0.2
2024-01-21 13:16:48 ------------------------
2024-01-21 13:16:48 
2024-01-21 13:16:48 
2024-01-21 13:16:49 Server is open to allow connections from anyone (0.0.0.0)
2024-01-21 13:16:49 basicAuth credentials are "admin:pass", it is recommended you change this in your config.js!
2024-01-21 13:16:49 Mongo Express server listening at http://0.0.0.0:8081

Is it normal that it's taking much time to load, or there's some issue because there are many invalid arguments in the Running Container picture.

I've been getting this since the beginning, I just started Docker

Nefen answered 21/1, 2024 at 7:56 Comment(2)
Same issue. No idea so far.Dozen
it works, but when I go to localhost:8081 and try to insert the user name and password I get 401 errorFabiolafabiolas
T
2

Both of these options should work:

Option 1:

  • In your mongodb service -> Add the container_name mongo
  • In your mongo-express service -> update the ME_CONFIG_MONGODB_SERVER name to mongo (updated in the step above) instead of mongodb
  mongodb:
    container_name: mongo
    image: mongo
    environment:
      MONGO_INITDB_ROOT_USERNAME: admin
      MONGO_INITDB_ROOT_PASSWORD: password
    ...
      
  mongo-express:
    container_name: mongo_express
    image: mongo-express
    restart: always
    ports:
      - 8081:8081
    environment:
      ME_CONFIG_BASICAUTH_USERNAME: browser_user
      ME_CONFIG_BASICAUTH_PASSWORD: browser_pass
      ME_CONFIG_MONGODB_ADMINUSERNAME: admin
      ME_CONFIG_MONGODB_ADMINPASSWORD: password
      ME_CONFIG_MONGODB_SERVER: mongo
    depends_on:
      - mongodb

Option 2:

  • Replace the key ME_CONFIG_MONGODB_SERVER with ME_CONFIG_MONGODB_URL: mongodb://admin:password@mongodb:27017/ (container_name not needed or with any name)
  mongodb:
    image: mongo
    environment:
      MONGO_INITDB_ROOT_USERNAME: admin
      MONGO_INITDB_ROOT_PASSWORD: password
    ...
      
  mongo-express:
    container_name: mongo_express
    image: mongo-express
    restart: always
    ports:
      - 8081:8081
    environment:
      ME_CONFIG_BASICAUTH_USERNAME: browser_user
      ME_CONFIG_BASICAUTH_PASSWORD: browser_pass
      ME_CONFIG_MONGODB_ADMINUSERNAME: admin
      ME_CONFIG_MONGODB_ADMINPASSWORD: password
      ME_CONFIG_MONGODB_URL: mongodb://admin:password@mongodb:27017/
    depends_on:
      - mongodb

I hope this helps!

Tarratarradiddle answered 13/8, 2024 at 10:5 Comment(1)
Tested Option 1 with success. ThanksFantasia
V
1

The latest version of mongo-express replaced ME_CONFIG_MONGODB_SERVER with ME_CONFIG_MONGODB_URL. That's the reason, it says Invalid argument. So add 0.54.0 to the image.

Change image: mongo-express to image: mongo-express:0.54.0. This will work.

Velocipede answered 22/7, 2024 at 12:55 Comment(0)
B
0

Is it like your mongo container was not started yet and mongo express already trying to connect it? Then you should try to add dependency like this:

mongo-express:
 ...
 depends_on:
      - mongodb
Bijou answered 21/1, 2024 at 9:57 Comment(1)
doesnt work for me (Agc

© 2022 - 2025 — McMap. All rights reserved.