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:
db1:
image: postgres
db2:
image: tutum/mongodb
ports:
- "27017:27017"
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
links:
- 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/connection.py”, 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