Docker Community Forums

Share and learn in the Docker community.

Docker-compose to run django with mongodb and postgres

(Pragyagm) #1

Hi all, i am facing problem using docker-compose to link a django container with postgres as well as mongo container? I am trying to use “docker-compose up web” which starts up the mongo and postgres containers (as I need to link both) but still the django app is not able to connect to mongodb on default settings. My django-compose.yml file contents copied below:
image: postgres
image: tutum/mongodb
- "27017:27017"
build: .
command: python runserver
- .:/code
- "8000:8000"
- db1
- db2

It does connect with postgres with default settings. I can also telnet to the mongodb port locally. Still, I get this error on starting the web container:

File “/usr/local/lib/python2.7/site-packages/mongoengine/”, line 124, in get_connection web_1 | raise ConnectionError(“Cannot connect to database %s :\n%s” % (alias, e)) web_1 | mongoengine.connection.ConnectionError: Cannot connect to database default : web_1 | [Errno 111] Connection refused