首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >码头工人-不启动所有服务

码头工人-不启动所有服务
EN

Stack Overflow用户
提问于 2022-08-17 03:37:43
回答 1查看 51关注 0票数 0

我有两个服务(芒果和芒果快车)在码头-撰写文件。当我尝试启动文件时,docker只创建一个容器(mongo)。然后,如果我手动启动第二个容器(Mongo),那么它就能正常工作。

*.yaml

代码语言:javascript
复制
version: '3'
services:
  mongodb:
    container_name: mongo
    image: mongo:4.4.15
    ports:
      - "27017:27017"
    environment:
      - MONGO_INITDB_ROOT_USERNAME=admin
      - MONGO_INITDB_ROOT_PASSWORD=password

  mongo-express:
    container_name: mongo-express
    image: mongo-express
    ports:
      - "8081:8081"
    environment:
      - ME_CONFIG_MONGODB_ADMINUSERNAME=admin
      - ME_CONFIG_MONGODB_ADMINPASSWORD=password
      - ME_CONFIG_MONGODB_SERVER=mongodb

蒙古速递日志

代码语言:javascript
复制
mongo-express    | Welcome to mongo-express
mongo-express    | ------------------------
mongo-express    |
mongo-express    |
mongo-express    | (node:7) [MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
mongo-express    | Could not connect to database using connectionString: mongodb://admin:password@mongodb:27017/"
mongo-express    | (node:7) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [mongodb:27017] on first connect [Error: connect ECONNREFUSED 172.20.0.3:27017
mongo-express    |     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16) {
mongo-express    |   name: 'MongoNetworkError'
mongo-express    | }]
mongo-express    |     at Pool.<anonymous> (/node_modules/mongodb/lib/core/topologies/server.js:441:11)
mongo-express    |     at Pool.emit (events.js:314:20)
mongo-express    |     at /node_modules/mongodb/lib/core/connection/pool.js:564:14
mongo-express    |     at /node_modules/mongodb/lib/core/connection/pool.js:1000:11
mongo-express    |     at /node_modules/mongodb/lib/core/connection/connect.js:32:7
mongo-express    |     at callback (/node_modules/mongodb/lib/core/connection/connect.js:300:5)
mongo-express    |     at Socket.<anonymous> (/node_modules/mongodb/lib/core/connection/connect.js:330:7)
mongo-express    |     at Object.onceWrapper (events.js:421:26)
mongo-express    |     at Socket.emit (events.js:314:20)
mongo-express    |     at emitErrorNT (internal/streams/destroy.js:92:8)
mongo-express    |     at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
mongo-express    |     at processTicksAndRejections (internal/process/task_queues.js:84:21)
mongo-express    | (node:7) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
mongo-express    | (node:7) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled

我做错了什么吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-17 08:15:47

看起来mongodbmongo-express启动得太晚了。尝试添加depends_on,但我建议查看wait-for-it.sh以检查mongodb是否已启动。

代码语言:javascript
复制
version: '3'
services:
  mongodb:
    container_name: mongo
    image: mongo:4.4.15
    ports:
      - "27017:27017"
    environment:
      - MONGO_INITDB_ROOT_USERNAME=admin
      - MONGO_INITDB_ROOT_PASSWORD=password

  mongo-express:
    container_name: mongo-express
    image: mongo-express
    ports:
      - "8081:8081"
    environment:
      - ME_CONFIG_MONGODB_ADMINUSERNAME=admin
      - ME_CONFIG_MONGODB_ADMINPASSWORD=password
      - ME_CONFIG_MONGODB_SERVER=mongodb
    depends_on:
      - mongodb
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73382612

复制
相关文章

相似问题

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