I've been fiddling with my Dockerfile and Docker Compose to try and get PyCharm to be able to run and debug my django application. I've identified that I need all services to be on the same network, and have put them on the same network, but when I go to execute the runserver command through my PyCharm configuration, I get an error that
django.db.utils.OperationalError: could not translate host name "postgres" to address: Name or service not known
I've tried adjusting the Dockerfile to expose environment variables inside of it, instead of in the compose file. As well as grouping all the services into the same network. I'm at a bit of a loss as to where to go from here, as most other StackOverflow questions relating to this tell me to do things I've already tried.
docker-compose.yml
version: "2"
services:
redis:
image: redis:latest # redis
restart: always
logging:
driver: "none"
networks:
- integration
postgres:
image: postgres:latest
restart: always
ports:
- "5400:5399"
volumes:
- /usr/lib/postgresql
- ./tmp:/dmp:ro
- ./load.sh:/usr/app/load.sh
environment:
POSTGRES_USER: vagrant
POSTGRES_PASSWORD: vagrant
POSTGRES_HOST_AUTH_METHOD: trust
logging:
driver: none
networks:
- integration
django:
build: .
command: "/bin/bash"
working_dir: /usr/app/
stdin_open: true
tty: true
volumes:
- ./tmp:/tmp
- ./:/usr/app
- ~/.ssh:/root/.ssh:ro
links:
- redis:redis
- postgres:postgres
depends_on:
- postgres
environment:
DJANGO_SETTINGS_MODULE: project.settings.docker_local
DJANGO_DEBUG: "true"
SSH_AUTH_SOCK: /tmp/authsock
logging:
driver: none
networks:
- integration
networks:
integration:
driver: bridge
Dockerfile
FROM python:latest
RUN echo "installing requirements"
COPY requirements/ /usr/app/reqs/
RUN pip install -r /usr/app/reqs/base.txt
RUN pip install -r /usr/app/reqs/local.txt
ENV DJANGO_SETTINGS_MODULE=project.settings.docker_local
COPY . /usr/app/
RUN echo "done"
I have hooked up PyCharm with the remote interpreter living inside the django service, and it is able to recognize all of the installed packages.
I have a docker-compose configuration for building the containers within PyCharm, and a Django Server configuration for running the runserver command on the Django service.
Docker-Compose Config:
Django-Server Config:
Finally, here is the relevant portion of my settings file, docker_local.py
DATABASES = {
'default': dj_database_url.config(
default='postgres://vagrant:vagrant@postgres/vagrant'),
}
DATABASES['default']['ENGINE'] = 'django.contrib.gis.db.backends.postgis'
Any and all help or advice is greatly appreciated.

