skip to Main Content

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.

2

Answers


  1. Chosen as BEST ANSWER

    Update

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


  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search