mongo-express-docker: MongoError: failed to connect to server [mongo:27017] on first connect

version: '3'
services:

  mongodb:
    image: mongo
    restart: always

  mongo-express:
    image: mongo-express
    restart: always
    ports:
      - 8081:8081

os: mac

image

log

➜  docker-buff git:(master) ✗ docker-compose up --force-recreate --build
Recreating docker-buff_mongodb_1       ... done
Recreating docker-buff_mongo-express_1 ... done
Attaching to docker-buff_mongodb_1, docker-buff_mongo-express_1
mongodb_1        | 2019-08-01T13:13:36.797+0000 I CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
mongo-express_1  | Waiting for mongo:27017...
mongodb_1        | 2019-08-01T13:13:36.800+0000 I CONTROL  [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=4ab148edbc7b
mongodb_1        | 2019-08-01T13:13:36.800+0000 I CONTROL  [initandlisten] db version v4.0.11
mongodb_1        | 2019-08-01T13:13:36.800+0000 I CONTROL  [initandlisten] git version: 417d1a712e9f040d54beca8e4943edce218e9a8c
mongodb_1        | 2019-08-01T13:13:36.800+0000 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
mongodb_1        | 2019-08-01T13:13:36.800+0000 I CONTROL  [initandlisten] allocator: tcmalloc
mongodb_1        | 2019-08-01T13:13:36.800+0000 I CONTROL  [initandlisten] modules: none
mongodb_1        | 2019-08-01T13:13:36.800+0000 I CONTROL  [initandlisten] build environment:
mongodb_1        | 2019-08-01T13:13:36.800+0000 I CONTROL  [initandlisten]     distmod: ubuntu1604
mongodb_1        | 2019-08-01T13:13:36.800+0000 I CONTROL  [initandlisten]     distarch: x86_64
mongodb_1        | 2019-08-01T13:13:36.800+0000 I CONTROL  [initandlisten]     target_arch: x86_64
mongodb_1        | 2019-08-01T13:13:36.800+0000 I CONTROL  [initandlisten] options: { net: { bindIpAll: true } }
mongo-express_1  | /docker-entrypoint.sh: line 14: mongo: Name does not resolve
mongo-express_1  | /docker-entrypoint.sh: line 14: /dev/tcp/mongo/27017: Invalid argument
mongodb_1        | 2019-08-01T13:13:36.801+0000 I STORAGE  [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
mongodb_1        | 2019-08-01T13:13:36.801+0000 I STORAGE  [initandlisten]
mongodb_1        | 2019-08-01T13:13:36.801+0000 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
mongodb_1        | 2019-08-01T13:13:36.801+0000 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
mongodb_1        | 2019-08-01T13:13:36.801+0000 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=487M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
mongodb_1        | 2019-08-01T13:13:37.570+0000 I STORAGE  [initandlisten] WiredTiger message [1564665217:570928][1:0x7f4f04268a80], txn-recover: Main recovery loop: starting at 2/4992 to 3/256
mongodb_1        | 2019-08-01T13:13:37.682+0000 I STORAGE  [initandlisten] WiredTiger message [1564665217:682082][1:0x7f4f04268a80], txn-recover: Recovering log 2 through 3
mongodb_1        | 2019-08-01T13:13:37.755+0000 I STORAGE  [initandlisten] WiredTiger message [1564665217:754999][1:0x7f4f04268a80], txn-recover: Recovering log 3 through 3
mongo-express_1  | Thu Aug  1 13:13:37 UTC 2019 retrying to connect to mongo:27017 (2/5)
mongo-express_1  | /docker-entrypoint.sh: line 14: mongo: Name does not resolve
mongo-express_1  | /docker-entrypoint.sh: line 14: /dev/tcp/mongo/27017: Invalid argument
mongodb_1        | 2019-08-01T13:13:37.818+0000 I STORAGE  [initandlisten] WiredTiger message [1564665217:818295][1:0x7f4f04268a80], txn-recover: Set global recovery timestamp: 0
mongodb_1        | 2019-08-01T13:13:37.834+0000 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
mongodb_1        | 2019-08-01T13:13:37.844+0000 I CONTROL  [initandlisten]
mongodb_1        | 2019-08-01T13:13:37.844+0000 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
mongodb_1        | 2019-08-01T13:13:37.844+0000 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
mongodb_1        | 2019-08-01T13:13:37.844+0000 I CONTROL  [initandlisten]
mongodb_1        | 2019-08-01T13:13:37.865+0000 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
mongodb_1        | 2019-08-01T13:13:37.867+0000 I NETWORK  [initandlisten] waiting for connections on port 27017
mongo-express_1  | Thu Aug  1 13:13:38 UTC 2019 retrying to connect to mongo:27017 (3/5)
mongo-express_1  | /docker-entrypoint.sh: line 14: mongo: Name does not resolve
mongo-express_1  | /docker-entrypoint.sh: line 14: /dev/tcp/mongo/27017: Invalid argument
mongo-express_1  | Thu Aug  1 13:13:39 UTC 2019 retrying to connect to mongo:27017 (4/5)
mongo-express_1  | /docker-entrypoint.sh: line 14: mongo: Name does not resolve
mongo-express_1  | /docker-entrypoint.sh: line 14: /dev/tcp/mongo/27017: Invalid argument
mongo-express_1  | Thu Aug  1 13:13:40 UTC 2019 retrying to connect to mongo:27017 (5/5)
mongo-express_1  | /docker-entrypoint.sh: line 14: mongo: Name does not resolve
mongo-express_1  | /docker-entrypoint.sh: line 14: /dev/tcp/mongo/27017: Invalid argument
mongo-express_1  | Welcome to mongo-express
mongo-express_1  | ------------------------
mongo-express_1  |
mongo-express_1  |
mongo-express_1  | Mongo Express server listening at http://0.0.0.0:8081
mongo-express_1  | Server is open to allow connections from anyone (0.0.0.0)
mongo-express_1  | basicAuth credentials are "admin:pass", it is recommended you change this in your config.js!
mongo-express_1  |
mongo-express_1  | /node_modules/mongodb/lib/server.js:265
mongo-express_1  |         process.nextTick(function() { throw err; })
mongo-express_1  |                                       ^
mongo-express_1  | MongoError: failed to connect to server [mongo:27017] on first connect
mongo-express_1  |     at Pool.<anonymous> (/node_modules/mongodb-core/lib/topologies/server.js:326:35)
mongo-express_1  |     at emitOne (events.js:116:13)
mongo-express_1  |     at Pool.emit (events.js:211:7)
mongo-express_1  |     at Connection.<anonymous> (/node_modules/mongodb-core/lib/connection/pool.js:270:12)
mongo-express_1  |     at Object.onceWrapper (events.js:317:30)
mongo-express_1  |     at emitTwo (events.js:126:13)
mongo-express_1  |     at Connection.emit (events.js:214:7)
mongo-express_1  |     at Socket.<anonymous> (/node_modules/mongodb-core/lib/connection/connection.js:175:49)
mongo-express_1  |     at Object.onceWrapper (events.js:315:30)
mongo-express_1  |     at emitOne (events.js:116:13)
mongo-express_1  | Thu Aug  1 13:13:49 UTC 2019 retrying to connect to mongo:27017 (2/5)
mongo-express_1  | /docker-entrypoint.sh: line 14: mongo: Name does not resolve
mongo-express_1  | /docker-entrypoint.sh: line 14: /dev/tcp/mongo/27017: Invalid argument
mongo-express_1  | Thu Aug  1 13:13:50 UTC 2019 retrying to connect to mongo:27017 (3/5)
mongo-express_1  | /docker-entrypoint.sh: line 14: mongo: Name does not resolve
mongo-express_1  | /docker-entrypoint.sh: line 14: /dev/tcp/mongo/27017: Invalid argument
mongo-express_1  | Thu Aug  1 13:13:51 UTC 2019 retrying to connect to mongo:27017 (4/5)
mongo-express_1  | /docker-entrypoint.sh: line 14: mongo: Name does not resolve
mongo-express_1  | /docker-entrypoint.sh: line 14: /dev/tcp/mongo/27017: Invalid argument
mongo-express_1  | Thu Aug  1 13:13:52 UTC 2019 retrying to connect to mongo:27017 (5/5)
mongo-express_1  | /docker-entrypoint.sh: line 14: mongo: Name does not resolve
mongo-express_1  | /docker-entrypoint.sh: line 14: /dev/tcp/mongo/27017: Invalid argument
mongo-express_1  | Welcome to mongo-express
mongo-express_1  | ------------------------
mongo-express_1  |
mongo-express_1  |
mongo-express_1  | Mongo Express server listening at http://0.0.0.0:8081
mongo-express_1  | Server is open to allow connections from anyone (0.0.0.0)
mongo-express_1  | basicAuth credentials are "admin:pass", it is recommended you change this in your config.js!
mongo-express_1  |
mongo-express_1  | /node_modules/mongodb/lib/server.js:265
mongo-express_1  |         process.nextTick(function() { throw err; })
mongo-express_1  |                                       ^
mongo-express_1  | MongoError: failed to connect to server [mongo:27017] on first connect
mongo-express_1  |     at Pool.<anonymous> (/node_modules/mongodb-core/lib/topologies/server.js:326:35)
mongo-express_1  |     at emitOne (events.js:116:13)
mongo-express_1  |     at Pool.emit (events.js:211:7)
mongo-express_1  |     at Connection.<anonymous> (/node_modules/mongodb-core/lib/connection/pool.js:270:12)
mongo-express_1  |     at Object.onceWrapper (events.js:317:30)
mongo-express_1  |     at emitTwo (events.js:126:13)
mongo-express_1  |     at Connection.emit (events.js:214:7)
mongo-express_1  |     at Socket.<anonymous> (/node_modules/mongodb-core/lib/connection/connection.js:175:49)
mongo-express_1  |     at Object.onceWrapper (events.js:315:30)
mongo-express_1  |     at emitOne (events.js:116:13)
docker-buff_mongo-express_1 exited with code 1
^CGracefully stopping... (press Ctrl+C again to force)
Stopping docker-buff_mongodb_1         ... done
Stopping docker-buff_mongo-express_1   ... done
➜  docker-buff git:(master) ✗

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 7
  • Comments: 22

Most upvoted comments

version: "3.7"
services:
  mongodb:
    container_name: mongo-dev
    image: mongo
    environment:
      - MONGO_INITDB_ROOT_USERNAME=admin
      - MONGO_INITDB_DATABASE=auth
      - MONGO_INITDB_ROOT_PASSWORD=pass
    ports:
      - '27017:27017'
  mongo-express:
    container_name: mongo-express
    image: mongo-express
    depends_on:
      - mongodb
    environment:
      - ME_CONFIG_MONGODB_ADMINUSERNAME=admin
      - ME_CONFIG_MONGODB_ADMINPASSWORD=pass
      - ME_CONFIG_MONGODB_SERVER=mongo-dev
      - ME_CONFIG_BASICAUTH_USERNAME=admin
      - ME_CONFIG_BASICAUTH_PASSWORD=ihavealongpassword
    ports:
      - '8081:8081'

This recipe works for me. remember to add depends_on. mongo-express may start before mongodb.

@Zeka13, The ticket is closed, because, it is not an image problem, but a configuration problem. In order to solve this problem, you need to specify for the mongo-express image, in the environment section, the server address by the name of the mongo container. How it was done by @leon0707.

version: "3.7"
services:
  mongodb:
    container_name: mongo-dev

and

mongo-express:
    container_name: mongo-express
    image: mongo-express
    depends_on:
      - mongodb
    environment:
     ...
      - ME_CONFIG_MONGODB_SERVER=mongo-dev
     ...

No matter what you do express mongo never connects.

This worked for me, I updated the docker-compose file and set the version that worked for me.

I had:

image: mongo-express

I updated it to:

image: mongo-express:0.54.0

I have run exactly into the same problem when using MongoDB and mongo-express. The only way to resolve the issue is to add a restart: always property, this property will restart the container if it stops.

https://docs.docker.com/config/containers/start-containers-automatically/

Regards, Alex.

Solved: This problem comes when your database uses a volumes configuration, but mongodb and mongo-express doesn’t share a network configuration. This worked perfectly for me:

version: "3.7"

services:
  db:
    container_name: mongo-dev
    image: mongo:4.2
    environment:
      - MONGO_INITDB_ROOT_USERNAME=admin
      - MONGO_INITDB_DATABASE=auth
      - MONGO_INITDB_ROOT_PASSWORD=pass
    networks: 
      - mongo-compose-network
    ports:
      - '27017:27017'
    volumes: 
      - ./data:/data/db
  
  mongo-express:
    container_name: mongo-express
    image: mongo-express
    depends_on:
      - db
    networks: 
      - mongo-compose-network
    environment:
      - ME_CONFIG_MONGODB_SERVER=mongo-dev
      - ME_CONFIG_MONGODB_ADMINUSERNAME=admin
      - ME_CONFIG_MONGODB_ADMINPASSWORD=pass
      - ME_CONFIG_BASICAUTH_USERNAME=admin
      - ME_CONFIG_BASICAUTH_PASSWORD=tribes
    ports:
      - '8081:8081'
    volumes: 
      - ./data:/data/db      

networks:
  mongo-compose-network:
    driver: bridge
```yaml
version: '3.7'
services:
  mongo-express:
    container_name: mongo-express
    image: mongo-express
    restart: always 

    depends_on:
      - mongodb
    environment:
      - ME_CONFIG_MONGODB_SERVER=mongo
      - ME_CONFIG_MONGODB_PORT=27017
      - ME_CONFIG_MONGODB_ADMINUSERNAME=${DB_USERNAME}
      - ME_CONFIG_MONGODB_ADMINPASSWORD=${DB_PASSWORD}
    ports:
      - 8081:8081
    networks: 
      - mongo-compose-network

  MongoDB:
    container_name: mongo
    image: mongo
    # restart: always

    environment:
      - MONGO_INITDB_ROOT_USERNAME=${DB_USERNAME}
      - MONGO_INITDB_ROOT_PASSWORD=${DB_PASSWORD}
    volumes: 
      - ../database:/data/db
    ports: 
      - 27017:27017
    networks: 
      - mongo-compose-network

networks:
  mongo-compose-network:
    driver: bridge

This is my docker-compose.yml. Howerver, It doesn’t work. The errors is:

mongo-express exited with code 0
mongo-express  | Welcome to mongo-express
mongo-express  | ------------------------
mongo-express  | 
mongo-express  | 
mongo-express  | (node:7) [MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
mongo-express  | Could not connect to database using connectionString: mongodb://root:12345678@mongo:27017/"
mongo-express  | (node:7) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [mongo:27017] on first connect [MongoError: Authentication failed.
mongo-express  |     at Connection.messageHandler (/node_modules/mongodb/lib/core/connection/connection.js:364:19)
mongo-express  |     at Connection.emit (events.js:314:20)
mongo-express  |     at processMessage (/node_modules/mongodb/lib/core/connection/connection.js:456:10)
mongo-express  |     at Socket.<anonymous> (/node_modules/mongodb/lib/core/connection/connection.js:625:15)
mongo-express  |     at Socket.emit (events.js:314:20)
mongo-express  |     at addChunk (_stream_readable.js:297:12)
mongo-express  |     at readableAddChunk (_stream_readable.js:272:9)
mongo-express  |     at Socket.Readable.push (_stream_readable.js:213:10)
mongo-express  |     at TCP.onStreamRead (internal/stream_base_commons.js:188:23) {
mongo-express  |   ok: 0,
mongo-express  |   code: 18,
mongo-express  |   codeName: 'AuthenticationFailed'
mongo-express  | }]
mongo-express  |     at Pool.<anonymous> (/node_modules/mongodb/lib/core/topologies/server.js:441:11)
mongo-express  |     at Pool.emit (events.js:314:20)
mongo-express  |     at /node_modules/mongodb/lib/core/connection/pool.js:564:14
mongo-express  |     at /node_modules/mongodb/lib/core/connection/pool.js:1000:11
mongo-express  |     at callback (/node_modules/mongodb/lib/core/connection/connect.js:75:5)
mongo-express  |     at /node_modules/mongodb/lib/core/connection/connect.js:158:27
mongo-express  |     at /node_modules/mongodb/lib/core/auth/scram.js:187:14
mongo-express  |     at _callback (/node_modules/mongodb/lib/core/connection/connection.js:333:7)
mongo-express  |     at Connection.messageHandler (/node_modules/mongodb/lib/core/connection/connection.js:364:9)
mongo-express  |     at Connection.emit (events.js:314:20)
mongo-express  |     at processMessage (/node_modules/mongodb/lib/core/connection/connection.js:456:10)
mongo-express  |     at Socket.<anonymous> (/node_modules/mongodb/lib/core/connection/connection.js:625:15)
mongo-express  |     at Socket.emit (events.js:314:20)
mongo-express  |     at addChunk (_stream_readable.js:297:12)
mongo-express  |     at readableAddChunk (_stream_readable.js:272:9)
mongo-express  |     at Socket.Readable.push (_stream_readable.js:213:10)
mongo-express  | (node:7) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
mongo-express  | (node:7) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
mongo-express exited with code 0

I have solved my problem. I was using “volumes” to store my username and password, which resulted in me always using the old password while debugging, causing errors. Therefore, the key point is to ALWAYS remember to delete any volumes or containers that can cause such issues. Additionally, from the documentation, it can be inferred that if you start a container with an already existing database, none of the variables below will have any effect as the pre-existing database will always remain unaltered on container startup. Hope my mistake can help you!

@leon0707 That only works if you use the default ‘admin:pass’ credentials. It’s not doing anything with the ME_CONFIG_MONGODB_ADMINUSERNAME / ME_CONFIG_MONGODB_ADMINPASSWORD variables.

version: '3.7'
services:
  mongo-express:
    container_name: mongo-express
    image: mongo-express
    restart: always 

    depends_on:
      - mongodb
    environment:
      - ME_CONFIG_MONGODB_SERVER=mongo
      - ME_CONFIG_MONGODB_PORT=27017
      - ME_CONFIG_MONGODB_ADMINUSERNAME=${DB_USERNAME}
      - ME_CONFIG_MONGODB_ADMINPASSWORD=${DB_PASSWORD}
    ports:
      - 8081:8081
    networks: 
      - mongo-compose-network

  mongodb:
    container_name: mongo
    image: mongo
    # restart: always

    environment:
      - MONGO_INITDB_ROOT_USERNAME=${DB_USERNAME}
      - MONGO_INITDB_ROOT_PASSWORD=${DB_PASSWORD}
    volumes: 
      - ../database:/data/db
    ports: 
      - 27017:27017
    networks: 
      - mongo-compose-network

networks:
  mongo-compose-network:
    driver: bridge

This is my docker-compose.yml. Howerver, It doesn’t work. The errors is:

mongo-express exited with code 0
mongo-express  | Welcome to mongo-express
mongo-express  | ------------------------
mongo-express  | 
mongo-express  | 
mongo-express  | (node:7) [MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
mongo-express  | Could not connect to database using connectionString: mongodb://root:12345678@mongo:27017/"
mongo-express  | (node:7) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [mongo:27017] on first connect [MongoError: Authentication failed.
mongo-express  |     at Connection.messageHandler (/node_modules/mongodb/lib/core/connection/connection.js:364:19)
mongo-express  |     at Connection.emit (events.js:314:20)
mongo-express  |     at processMessage (/node_modules/mongodb/lib/core/connection/connection.js:456:10)
mongo-express  |     at Socket.<anonymous> (/node_modules/mongodb/lib/core/connection/connection.js:625:15)
mongo-express  |     at Socket.emit (events.js:314:20)
mongo-express  |     at addChunk (_stream_readable.js:297:12)
mongo-express  |     at readableAddChunk (_stream_readable.js:272:9)
mongo-express  |     at Socket.Readable.push (_stream_readable.js:213:10)
mongo-express  |     at TCP.onStreamRead (internal/stream_base_commons.js:188:23) {
mongo-express  |   ok: 0,
mongo-express  |   code: 18,
mongo-express  |   codeName: 'AuthenticationFailed'
mongo-express  | }]
mongo-express  |     at Pool.<anonymous> (/node_modules/mongodb/lib/core/topologies/server.js:441:11)
mongo-express  |     at Pool.emit (events.js:314:20)
mongo-express  |     at /node_modules/mongodb/lib/core/connection/pool.js:564:14
mongo-express  |     at /node_modules/mongodb/lib/core/connection/pool.js:1000:11
mongo-express  |     at callback (/node_modules/mongodb/lib/core/connection/connect.js:75:5)
mongo-express  |     at /node_modules/mongodb/lib/core/connection/connect.js:158:27
mongo-express  |     at /node_modules/mongodb/lib/core/auth/scram.js:187:14
mongo-express  |     at _callback (/node_modules/mongodb/lib/core/connection/connection.js:333:7)
mongo-express  |     at Connection.messageHandler (/node_modules/mongodb/lib/core/connection/connection.js:364:9)
mongo-express  |     at Connection.emit (events.js:314:20)
mongo-express  |     at processMessage (/node_modules/mongodb/lib/core/connection/connection.js:456:10)
mongo-express  |     at Socket.<anonymous> (/node_modules/mongodb/lib/core/connection/connection.js:625:15)
mongo-express  |     at Socket.emit (events.js:314:20)
mongo-express  |     at addChunk (_stream_readable.js:297:12)
mongo-express  |     at readableAddChunk (_stream_readable.js:272:9)
mongo-express  |     at Socket.Readable.push (_stream_readable.js:213:10)
mongo-express  | (node:7) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
mongo-express  | (node:7) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
mongo-express exited with code 0

The real issue of the original question was missing “ME_CONFIG_MONGODB_SERVER=mongo-dev”. Without that, mongo-express just try to connect to “mongo” instead of “mongo-dev”

Hi @avevlad if your rename your service name from ‘mongodb’ to ‘mongo’; the error of

mongo-express_1  | /docker-entrypoint.sh: line 14: mongo: Name does not resolve
mongo-express_1  | /docker-entrypoint.sh: line 14: /dev/tcp/mongo/27017: Invalid argument

will be resolved, … but there will be another error. Before that here is my docker-compose.yml

version: '3'

services:
  mongo:
    image: 'mongo:4'
    container_name: "mongodb_4"
    restart: always
    volumes:
      - ./datadir:/data/db
    #   - ./config/:/etc/
    environment:
      - MONGO_INITDB_ROOT_USERNAME=root
      - MONGO_INITDB_ROOT_PASSWORD=root
    #   - PGADMIN_DEFAULT_EMAIL=odoo
    #   - PGADMIN_DEFAULT_PASSWORD=odoo
    ports:
      - 27017:27017
    # network_mode: "bridge"
    networks:
        web_db_mongo:
          ipv4_address: 172.20.20.4
  mongo-express:
    image: mongo-express
    restart: always
    links:
      - mongo
    environment:
      - ME_CONFIG_MONGODB_ADMINUSERNAME=root
      - ME_CONFIG_MONGODB_ADMINPASSWORD=root
    ports:
      - 8111:8081
    networks:
        web_db_mongo:
          ipv4_address: 172.20.20.5

networks:
  web_db_mongo:
    external:
      name: docker_database_web

And the error is…

$ docker-compose down && docker-compose up
Removing mongo_mongo-express_1 ... done
Removing mongodb_4             ... done
Creating mongodb_4 ... done
Creating mongodb_4 ... 
Creating mongo_mongo-express_1 ... done
Attaching to mongodb_4, mongo_mongo-express_1
mongodb_4        | 2019-08-11T03:29:38.584+0000 I CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
mongo-express_1  | Waiting for mongo:27017...
mongodb_4        | 2019-08-11T03:29:38.589+0000 I CONTROL  [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=b6cd4306d73c
mongodb_4        | 2019-08-11T03:29:38.589+0000 I CONTROL  [initandlisten] db version v4.0.11
mongodb_4        | 2019-08-11T03:29:38.589+0000 I CONTROL  [initandlisten] git version: 417d1a712e9f040d54beca8e4943edce218e9a8c
mongodb_4        | 2019-08-11T03:29:38.589+0000 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
mongodb_4        | 2019-08-11T03:29:38.589+0000 I CONTROL  [initandlisten] allocator: tcmalloc
mongodb_4        | 2019-08-11T03:29:38.589+0000 I CONTROL  [initandlisten] modules: none
mongodb_4        | 2019-08-11T03:29:38.589+0000 I CONTROL  [initandlisten] build environment:
mongodb_4        | 2019-08-11T03:29:38.589+0000 I CONTROL  [initandlisten]     distmod: ubuntu1604
mongodb_4        | 2019-08-11T03:29:38.589+0000 I CONTROL  [initandlisten]     distarch: x86_64
mongodb_4        | 2019-08-11T03:29:38.589+0000 I CONTROL  [initandlisten]     target_arch: x86_64
mongodb_4        | 2019-08-11T03:29:38.589+0000 I CONTROL  [initandlisten] options: { net: { bindIpAll: true }, security: { authorization: "enabled" } }
mongodb_4        | 2019-08-11T03:29:38.590+0000 W STORAGE  [initandlisten] Detected unclean shutdown - /data/db/mongod.lock is not empty.
mongodb_4        | 2019-08-11T03:29:38.590+0000 I STORAGE  [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
mongodb_4        | 2019-08-11T03:29:38.590+0000 W STORAGE  [initandlisten] Recovering data from the last clean checkpoint.
mongodb_4        | 2019-08-11T03:29:38.590+0000 I STORAGE  [initandlisten] 
mongodb_4        | 2019-08-11T03:29:38.590+0000 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
mongodb_4        | 2019-08-11T03:29:38.590+0000 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
mongodb_4        | 2019-08-11T03:29:38.590+0000 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=5441M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
mongodb_4        | 2019-08-11T03:29:39.541+0000 I STORAGE  [initandlisten] WiredTiger message [1565494179:541047][1:0x7fc17743ba80], txn-recover: Main recovery loop: starting at 4/4608 to 5/256
mongodb_4        | 2019-08-11T03:29:39.542+0000 I STORAGE  [initandlisten] WiredTiger message [1565494179:542008][1:0x7fc17743ba80], txn-recover: Recovering log 4 through 5
mongodb_4        | 2019-08-11T03:29:39.669+0000 I STORAGE  [initandlisten] WiredTiger message [1565494179:669965][1:0x7fc17743ba80], txn-recover: Recovering log 5 through 5
mongodb_4        | 2019-08-11T03:29:39.740+0000 I STORAGE  [initandlisten] WiredTiger message [1565494179:740969][1:0x7fc17743ba80], txn-recover: Set global recovery timestamp: 0
mongodb_4        | 2019-08-11T03:29:40.044+0000 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
mongodb_4        | 2019-08-11T03:29:40.124+0000 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
mongodb_4        | 2019-08-11T03:29:40.125+0000 I NETWORK  [initandlisten] waiting for connections on port 27017
mongodb_4        | 2019-08-11T03:29:40.399+0000 I NETWORK  [listener] connection accepted from 172.20.20.5:41368 #1 (1 connection now open)
mongodb_4        | 2019-08-11T03:29:40.399+0000 I NETWORK  [conn1] end connection 172.20.20.5:41368 (0 connections now open)
mongo-express_1  | Welcome to mongo-express
mongo-express_1  | ------------------------
mongo-express_1  | 
mongo-express_1  | 
mongo-express_1  | Mongo Express server listening at http://0.0.0.0:8081
mongo-express_1  | Server is open to allow connections from anyone (0.0.0.0)
mongo-express_1  | basicAuth credentials are "admin:pass", it is recommended you change this in your config.js!
mongodb_4        | 2019-08-11T03:29:41.043+0000 I NETWORK  [listener] connection accepted from 172.20.20.5:41370 #2 (1 connection now open)
mongodb_4        | 2019-08-11T03:29:41.070+0000 I NETWORK  [conn2] received client metadata from 172.20.20.5:41370 conn2: { driver: { name: "nodejs", version: "2.2.24" }, os: { type: "Linux", name: "linux", architecture: "x64", version: "4.4.0-157-generic" }, platform: "Node.js v8.16.0, LE, mongodb-core: 2.1.8" }
mongo-express_1  | Database connected
mongodb_4        | 2019-08-11T03:29:41.080+0000 I ACCESS   [conn2] SASL SCRAM-SHA-1 authentication failed for root on admin from client 172.20.20.5:41370 ; UserNotFound: Could not find user root@admin
mongo-express_1  | { MongoError: Authentication failed.
mongo-express_1  |     at Function.MongoError.create (/node_modules/mongodb-core/lib/error.js:31:11)
mongo-express_1  |     at /node_modules/mongodb-core/lib/connection/pool.js:483:72
mongo-express_1  |     at authenticateStragglers (/node_modules/mongodb-core/lib/connection/pool.js:429:16)
mongo-express_1  |     at Connection.messageHandler (/node_modules/mongodb-core/lib/connection/pool.js:463:5)
mongo-express_1  |     at Socket.<anonymous> (/node_modules/mongodb-core/lib/connection/connection.js:319:22)
mongo-express_1  |     at emitOne (events.js:116:13)
mongo-express_1  |     at Socket.emit (events.js:211:7)
mongo-express_1  |     at addChunk (_stream_readable.js:263:12)
mongo-express_1  |     at readableAddChunk (_stream_readable.js:250:11)
mongo-express_1  |     at Socket.Readable.push (_stream_readable.js:208:10)
mongo-express_1  |   name: 'MongoError',
mongo-express_1  |   message: 'Authentication failed.',
mongo-express_1  |   ok: 0,
mongo-express_1  |   errmsg: 'Authentication failed.',
mongo-express_1  |   code: 18,
mongo-express_1  |   codeName: 'AuthenticationFailed' }
mongo-express_1  | Admin Database connected
mongo-express_1  | unable to list databases
mongo-express_1  | { MongoError: command listDatabases requires authentication
mongo-express_1  |     at Function.MongoError.create (/node_modules/mongodb-core/lib/error.js:31:11)
mongo-express_1  |     at /node_modules/mongodb-core/lib/connection/pool.js:483:72
mongo-express_1  |     at authenticateStragglers (/node_modules/mongodb-core/lib/connection/pool.js:429:16)
mongo-express_1  |     at Connection.messageHandler (/node_modules/mongodb-core/lib/connection/pool.js:463:5)
mongo-express_1  |     at Socket.<anonymous> (/node_modules/mongodb-core/lib/connection/connection.js:319:22)
mongo-express_1  |     at emitOne (events.js:116:13)
mongo-express_1  |     at Socket.emit (events.js:211:7)
mongo-express_1  |     at addChunk (_stream_readable.js:263:12)
mongo-express_1  |     at readableAddChunk (_stream_readable.js:250:11)
mongo-express_1  |     at Socket.Readable.push (_stream_readable.js:208:10)
mongo-express_1  |   name: 'MongoError',
mongo-express_1  |   message: 'command listDatabases requires authentication',
mongo-express_1  |   ok: 0,
mongo-express_1  |   errmsg: 'command listDatabases requires authentication',
mongo-express_1  |   code: 13,
mongo-express_1  |   codeName: 'Unauthorized' }

I’m running ubuntu 16.04 Gnome.

Any help for this is also welcomed.

Thanks in advance. 😃