首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mongo-Express:首次连接时无法连接到服务器[mongo:27017]

Mongo-Express:首次连接时无法连接到服务器[mongo:27017]
EN

Stack Overflow用户
提问于 2019-05-23 06:54:47
回答 2查看 3.3K关注 0票数 1

我正在尝试使用docker-compose运行最简单的mongomongo-express容器。我遇到了许多错误,稍后将对其进行解释。

我已经尝试了以下docker-compose配置:

1.

代码语言:javascript
复制
version: '2'
services:
    mongo:
        image: mongo:latest
    mongo-express:
        image: mongo-express:latest
        ports:
            - 8082:8081

2.

代码语言:javascript
复制
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时,它们都有以下常见的错误

代码语言:javascript
复制
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存储库中搜索了这个问题,并尝试了其他解决方案,但没有一个能正常工作。

link1 | link2 | link3 | link4 |等。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-05-29 18:18:19

首先,我运行了docker stop $(docker ps -a -q),然后将docker-compose.yml文件更改为以下内容:

代码语言:javascript
复制
version: '2'
services:
  mongo:
    image: mongo:3.4
    container_name: mongo
    ports:
      - '27017:27017'
    volumes: 
      - '/data/configdb:/data/configdb'
      - '/data/db:/data/db'
  mongo-express:
    image: mongo-express:0.49.0
    container_name: mongo_express
    depends_on:
      - 'mongo'
    ports:
      - '5050:8081'
    environment:
      - 'ME_CONFIG_OPTIONS_EDITORTHEME=ambiance'
票数 2
EN

Stack Overflow用户

发布于 2021-02-11 04:40:58

代码语言:javascript
复制
docker run -d 
-p 8081:8081 
--name mongo-express 
-e ME_CONFIG_MONGODB_ADMINUSERNAME=**<username>** 
-e ME_CONFIG_MONGODB_ADMINPASSWORD=**<password>** 
--net **<mongo network name>** 
-e ME_CONFIG_MONGODB_SERVER=**<mongodb container name>** 
-e ME_CONFIG_OPTIONS_EDITORTHEME=ambiance 
mongo-express
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56265985

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档