Dockerized MongoDB无法从NodeJs Container连接到Heroku

时间:2019-05-30 16:38:39

标签: node.js mongodb docker heroku

我有一个节点Web服务,而我对Docker有点陌生,所以请多多包涵。以下是我的docker-compose文件。我已经在本地运行此映像,并且可以正常工作,但是当尝试将其部署到Heroku时,出现以下错误:

{ MongoError: failed to connect to server [mongo:27017] on first connect [MongoError: getaddrinfo ENOTFOUND mongo mongo:27017]

我已经找到了应该在Heroku中设置环境标志的位置,因此我设法对其进行了检查。但它仍然找不到mongo:27017

我可能做错了什么?

version: "3"
services:
  mongo:
    container_name: mongo
    image: mongo
    volumes:
      - ./data:/data/charecters
    ports:
      - "27017:27017"
    environment:
      - MONGO_INITDB_ROOT_USERNAME=admin
      - MONGO_INITDB_ROOT_PASSWORD=password
  mongo-seed:
    build: ./mongo-seed
    links:
      - mongo
    volumes:
      - ./mongo-seed:/mongo-seed
    command:
      - /mongo-seed/script.sh
  app:
    container_name: app
    restart: always
    build: .
    ports:
      - "3000:3000"
    links:
      - mongo
    environment:
      - DB_SERVERS=mongo:27017

1 个答案:

答案 0 :(得分:-3)

links:
      - mongo

is depreciated try 

depends_on:
     - mongo

also, check that 

mongo:
    container_name: mongo, is properly referenced in DB setup

change command:
  - /mongo-seed/script.sh

try command:
   - 'node your-app-file'