docker-compose to run django with mongodb

前端 未结 4 710
执念已碎
执念已碎 2021-02-13 20:25

I am facing problem using docker-compose to link a django container with postgres and mongo containers? I am trying to use \"docker-compose up\" which starts up the mongo and po

4条回答
  •  南笙
    南笙 (楼主)
    2021-02-13 20:51

    You should specify host name like in the docker compose file, instead of IP address.

    I've faced similar problems in connecting from a Tornado Web app to Mongo DB. Here is my docker-compose.yml:

    web:
      build: .
      ports:
       - "8888:8888"
      volumes:
       - .:/code
      links:
       - db
    db:
      image: mongo:3.0
    

    Here is my connection string:

    motorengine.connect("db", host='db', port=27017, io_loop=io_loop)
    

    My error was to specify IP address instead of host name (db) like in the docker compose file.

提交回复
热议问题