mongo-express: docker-entrypoint.sh: connect: Connection refused

Hello, for some reason the image stopped working for me and it’s throwing ERR_EMPTY_RESPONSE.

This is my docker-compose.yml

version: "3"
services:
  node:
    image: "node:alpine"
    user: "node"
    working_dir: /home/node/app
    environment:
    - NODE_ENV=development
    volumes:
    - ./:/home/node/app
    ports:
    - "8888:8888"
    command: "./node_modules/.bin/nodemon server.js"
  mongo:
    image: 'mvertes/alpine-mongo'
    ports:
    - "27017:27017"
    volumes:
    - "./data/db:/data/db"
    links:
      - "mongo-express"
  mongo-express:
    image: 'mongo-express'
    ports:
    - "8081:8081"
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  | Tue Oct  9 15:49:56 UTC 2018 retrying to connect to mongo:27017 (2/5)
mongo-express_1  | /docker-entrypoint.sh: connect: Connection refused
mongo-express_1  | /docker-entrypoint.sh: line 14: /dev/tcp/mongo/27017: Connection refused
mongo_1          | 2018-10-09T15:49:56.084+0000 I CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
node_1           | [nodemon] 1.18.3
node_1           | [nodemon] to restart at any time, enter `rs`
node_1           | [nodemon] watching: *.*
node_1           | [nodemon] starting `node server.js`
mongo_1          | 2018-10-09T15:49:56.118+0000 I CONTROL  [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=5dbfbdb03286
mongo_1          | 2018-10-09T15:49:56.118+0000 I CONTROL  [initandlisten] db version v4.0.1
mongo_1          | 2018-10-09T15:49:56.119+0000 I CONTROL  [initandlisten] git version: 54f1582fc6eb01de4d4c42f26fc133e623f065fb
mongo_1          | 2018-10-09T15:49:56.120+0000 I CONTROL  [initandlisten] OpenSSL version: LibreSSL 2.7.4
mongo_1          | 2018-10-09T15:49:56.120+0000 I CONTROL  [initandlisten] allocator: system
mongo_1          | 2018-10-09T15:49:56.121+0000 I CONTROL  [initandlisten] modules: none
mongo_1          | 2018-10-09T15:49:56.121+0000 I CONTROL  [initandlisten] build environment:
mongo_1          | 2018-10-09T15:49:56.122+0000 I CONTROL  [initandlisten]     distarch: x86_64
mongo_1          | 2018-10-09T15:49:56.123+0000 I CONTROL  [initandlisten]     target_arch: x86_64
mongo_1          | 2018-10-09T15:49:56.123+0000 I CONTROL  [initandlisten] options: { net: { bindIp: "0.0.0.0" } }
mongo_1          | 2018-10-09T15:49:56.129+0000 I STORAGE  [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
mongo_1          | 2018-10-09T15:49:56.129+0000 I STORAGE  [initandlisten]
mongo_1          | 2018-10-09T15:49:56.129+0000 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
mongo_1          | 2018-10-09T15:49:56.129+0000 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
mongo_1          | 2018-10-09T15:49:56.132+0000 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=256M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,co
mpressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
mongo-express_1  | Tue Oct  9 15:49:57 UTC 2018 retrying to connect to mongo:27017 (3/5)
mongo-express_1  | /docker-entrypoint.sh: connect: Connection refused
mongo-express_1  | /docker-entrypoint.sh: line 14: /dev/tcp/mongo/27017: Connection refused
mongo-express_1  | Tue Oct  9 15:49:58 UTC 2018 retrying to connect to mongo:27017 (4/5)
mongo-express_1  | /docker-entrypoint.sh: connect: Connection refused
mongo-express_1  | /docker-entrypoint.sh: line 14: /dev/tcp/mongo/27017: Connection refused
mongo-express_1  | Tue Oct  9 15:49:59 UTC 2018 retrying to connect to mongo:27017 (5/5)
mongo-express_1  | /docker-entrypoint.sh: connect: Connection refused
mongo-express_1  | /docker-entrypoint.sh: line 14: /dev/tcp/mongo/27017: Connection refused
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)
mongodb-test_mongo-express_1 exited with code 1
mongo_1          | 2018-10-09T15:50:01.843+0000 I STORAGE  [initandlisten] WiredTiger message [1539100201:843819][1:0x7fda7a338960], txn-recover: Main recovery loop: starting at 14/7296
mongo_1          | 2018-10-09T15:50:03.608+0000 I STORAGE  [initandlisten] WiredTiger message [1539100203:608695][1:0x7fda7a338960], txn-recover: Recovering log 14 through 15
mongo_1          | 2018-10-09T15:50:04.487+0000 I STORAGE  [initandlisten] WiredTiger message [1539100204:487750][1:0x7fda7a338960], txn-recover: Recovering log 15 through 15
mongo_1          | 2018-10-09T15:50:05.344+0000 I STORAGE  [initandlisten] WiredTiger message [1539100205:344173][1:0x7fda7a338960], txn-recover: Set global recovery timestamp: 0
mongo_1          | 2018-10-09T15:50:05.403+0000 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
mongo_1          | 2018-10-09T15:50:05.457+0000 I CONTROL  [initandlisten]
mongo_1          | 2018-10-09T15:50:05.458+0000 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
mongo_1          | 2018-10-09T15:50:05.458+0000 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
mongo_1          | 2018-10-09T15:50:05.459+0000 I CONTROL  [initandlisten]
mongo_1          | 2018-10-09T15:50:05.460+0000 I CONTROL  [initandlisten]
mongo_1          | 2018-10-09T15:50:05.461+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
mongo_1          | 2018-10-09T15:50:05.462+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
mongo_1          | 2018-10-09T15:50:05.463+0000 I CONTROL  [initandlisten]
mongo_1          | 2018-10-09T15:50:05.552+0000 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
mongo_1          | 2018-10-09T15:50:05.557+0000 I NETWORK  [initandlisten] waiting for connections on port 27017

Any advice on this? I’m running docker inside an ubuntu vm (18.04.1 LTS)

About this issue

Most upvoted comments

Add Environment

ME_CONFIG_MONGODB_SERVER: mongo

I think this could help:

mongo:
  image: mongo
  container_name: mongo
  restart: always
  environment:
    MONGO_INITDB_ROOT_USERNAME: root
    MONGO_INITDB_ROOT_PASSWORD: example
  ports:
    - 27017:27017

mongo-express:
  image: mongo-express
  restart: always
  ports:
    - 8081:8081
  environment:
    ME_CONFIG_MONGODB_ADMINUSERNAME: root
    ME_CONFIG_MONGODB_ADMINPASSWORD: example
  links:
    - "mongo"

I just inserted this in mongo-express service:

links:
    - "mongo"

Had the same issue. Adding container_name: mongo to the the mongo service fixed it.

facing same problem

I was able to locally run in docker with this config:

version: '3.7'

services:

  mongodb:
    container_name: mongodb
    image: mongo
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: "123456"
      MONGO_INITDB_DATABASE: admin
    networks:
      - my-net
    ports:
      - "27017:27017"
    volumes:
      - ./mongodb:/data/db

  mongo-express:
    container_name: mongo-express
    image: mongo-express
    networks:
      - my-net
    ports:
      - 8081:8081
    environment:
      ME_CONFIG_MONGODB_ENABLE_ADMIN: true
      ME_CONFIG_BASICAUTH_USERNAME: root
      ME_CONFIG_BASICAUTH_PASSWORD: "123456"
      ME_CONFIG_MONGODB_URL: "mongodb://root:123456@host.docker.internal:27017/admin?ssl=false"	
      ME_CONFIG_MONGODB_PORT: 27017
    links:
      - mongodb

networks: 
    my-net:
      driver: bridge

DO NOT CHANGE ANYTHING! Somehow this is what could be done for local development LOL

FIXED - changed the me metadata for express.yaml to mongo-express-service instead of mongodb-express-service & changed selector-mongo-express instead of mongodb-express