Can't connect mysql database on another host machine from django container deployed on portainer

I have a django docker container deployed on portainer. In settings.py, I specified the ip of where my database is hosted. For some reason it is always redirected to the ip of portainer's host machine.

PS. I'm using nginx proxy manager for reverse proxy.

Needs to be on same docker network to communicate as isolated!

version: '3'
services:
  db:
    container_name: postgres
    image: postgres
    restart: always
    ports:
      - 5432:5432
    volumes:
      - db:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: user 
      POSTGRES_PASSWORD: password
      POSTGRES_DB: dbname
    networks:
      - mystack


  app:
    container_name: app-python
    image: myimage
    restart: always
    ports:
      - 8080:8080
    volumes:
      - app:/data
    networks:
      - mystack
  
volumes:
    db: {}
    app: {}

networks:
  mystack:

Example you can connect to the database simple using db:5432. db is the service name and also address to container accessible from any container on mystack network.

Update

I found the problem. Turns out it's just a firewall blocking my connection.

Back to Top