如果以/ data / db卷启动,则Docker mongo-express无法连接到mongo

时间:2020-01-28 22:33:44

标签: mongodb docker

我有一个以docker-compose up开头的docker-compose.yml,并且可以正常工作。

version: "3"

services:
  mongo:
    image: mongo
    restart: always
    ports:
      - 27017-27019:27017-27019
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: example
      MONGO_INITDB_DATABASE: brandRegistry
    volumes:
      - ./setup/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
      # - ./data/mongo-volume:/data/db

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

但是,如果我在日志中评论- ./data/mongo-volume:/data/db说:

mongo-express_1  | Tue Jan 28 22:21:16 UTC 2020 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

我看不出这与音量有何关系... 我想存储持久数据。你有小费吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

我只是没有等待足够长的时间。如果从容器外部的数据量开始,Mongo需要更长的时间。 mongo-express将尝试一次又一次地连接。一段时间后,它将成功。