[Python] Cannot connect to Mongo Atlas from Flask App inside Docker with Nginx

Discussão em 'Python' iniciado por Stack, Julho 12, 2025.

  1. Stack

    Stack Membro Participativo

    I am failing to get my App to connect the Atlas DB from behind nginx inside Docker.

    Here is my docker-compose.yml after trying to set up haproxy and failing to get through. Everything works when no behind SSL, have tried using IP addresses but cannot get through. IP address is whitelisted. Works fine in dev. just not when in prod and cannot figure out what I can do.

    I would not have used Atlas if I knew it was this much trouble to connect.

    services:
    nginx:
    image: nginx:latest
    volumes:
    - ./nginx/conf.d:/etc/nginx/conf.d
    - ./nginx/certbot/conf:/etc/letsencrypt
    - ./nginx/certbot/www:/var/www/certbot
    - ./static:/var/www/static
    ports:
    - "80:80"
    - "443:443"
    depends_on:
    - app
    networks:
    - qdosnet
    restart: on-failure

    app:
    image: uvuume/qdosprmanager-app:latest
    container_name: qdosmanager
    expose:
    - 5000
    volumes:
    - ./static/images:/var/www/static/images
    - ./resolv.docker.conf:/etc/resolv.conf:ro
    environment:
    PYTHONUNBUFFERED: 1
    env_file: env.prod
    command: gunicorn --timeout 120 -b 0.0.0.0:5000 app.app:app
    networks:
    - qdosnet

    haproxy:
    image: haproxy:latest
    volumes:
    - ./etc/haproxy/haproxy.cfg/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
    - ./resolv.docker.conf:/etc/resolv.conf:ro
    ports:
    - "27018:27018"
    networks:
    - qdosnet
    restart: always


    networks:
    qdosnet:
    driver: bridge


    Any advice on what I can do?

    Have not tried to set network to Host as that exposes network.

    Continue reading...

Compartilhe esta Página