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
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
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.
and
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:
I updated it to:
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:
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.
This is my docker-compose.yml. Howerver, It doesn’t work. The errors is:
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
will be resolved, … but there will be another error. Before that here is my docker-compose.yml
And the error is…
I’m running ubuntu 16.04 Gnome.
Any help for this is also welcomed.
Thanks in advance. 😃