【发布时间】:2021-02-11 04:40:57
【问题描述】:
我正在尝试使用docker-compose 运行mongo 和mongo-express 的最简单容器。我遇到了很多错误,稍后会解释。
我尝试了以下 docker-compose 配置:
1.
version: '2'
services:
mongo:
image: mongo:latest
mongo-express:
image: mongo-express:latest
ports:
- 8082:8081
2.
version: '2'
services:
mongo:
image: mongo:latest
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: root
ports:
- 27017:27017
volumes:
- db-data:/data/db
- mongo-config:/data/configdb
mongo-express:
image: mongo-express
restart: always
ports:
- 8081:8081
volumes:
db-data:
mongo-config:
等等。但是每当我执行docker-compose -f docker-compose.yml up时,它们都会出现以下常见错误:
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)
我已经在整个互联网和 github 存储库中搜索了这个问题,并尝试了其他解决方案,但没有一个能正常工作。
【问题讨论】:
-
看起来您还需要在
docker-express容器上反映环境变量。见hub.docker.com/_/…。您还应该考虑使用 docker-compose v3(作为示例)。
标签: mongodb docker docker-compose