Docker Compose with NGINX proxy pass thru not working

EDIT:

You’re currently not using the nginx configuration. I didn’t read carefully your docker-compose file. You can fix it by mapping the webapp.conf on /etc/nginx/conf.d/default.conf. e.g.

services:
 
  web:
    image: nginx
    volumes:
      - ./data/ntemplates:/etc/nginx/templates
      - ./webapp.conf:/etc/nginx/conf.d/default.conf
    ports:
      - "8080:80"
    depends_on:
      - pyweb
    networks:
      - webapp

There are 2 issues:

  • you don’t know what container name will be used by docker-compose
  • you don’t know the order used to start the containers

docker-compose allows you to solve the first issue in 2 ways:

  • define a container_name subsection
  • use the service name

This means that you can simply use proxy_pass "http://pyweb:5000/"; in your nginx setup

The second issue can be fixed by adding a depends_on subsection in the nginx service. e.g.

services:
 
  web:
    image: nginx
    volumes:
      - ./data/ntemplates:/etc/nginx/templates
      - ./webapp.conf:/etc/nginx/conf.d/webapp.conf
    depends_on:
      - pyweb
    ports:
      - "8080:80"
    networks:
      - webapp

Nevertheless, the depends_on might not be enough since it does not check the service status but it only make sure that the docker service is started (as stated in the documentation).

You’ll need to find another way to monitor if the service is actually started.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top