Dockerize nginx

In the documentation of ShinyProxy, there are instructions on how to dockerize ShinyProxy. There are also instructions on how to use nginx as a reverse proxy.
However, it would be great if nginx could be dockerized as well.
Based on the following link, I created a nginx config file, but it just launches ShinyProxy, and not the apps containers.

worker_processes 1;
events { worker_connections 1024; }
http {
  sendfile on;
  upstream shinyProxy {
      server shinyproxy:8080;
  }

  server {
      listen 80;

      location / {
          proxy_pass         http://shinyProxy;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
          proxy_read_timeout 600s;

          proxy_redirect    off;
          proxy_set_header  Host             $http_host;
          proxy_set_header  X-Real-IP        $remote_addr;
          proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
          proxy_set_header  X-Forwarded-Protocol $scheme;
      }
  }
}

and my docker-compose file

version: "3"

services:
  reverseproxy:
    build:
      context: .
      dockerfile: reverse.Dockerfile
    ports:
      - 80:80
    restart: always

  shinyproxy:
    build:
      context: .
      dockerfile: shinyProxy.Dockerfile

networks:
  default:
    external:
      name: sp-example-net

ShinyProxy.Dockerfile is this the same as the openanalytics/shinyproxy-config-examples repository
reverse.Dockerfile is just the nginx container with the config file.

Do you have any idea of what is wrong with that config?

Best!

1 Like

Your upstream network is wrong and pointing back to the “shinyproxy” container and not the “App” container. If running the example app the upstream network (and proxy_pass) should be something like:
docker-shinyproxy-example or shinyproxy-example. I haven’t set that up in some time

1 Like

Thank you so much! It runs perfectly now!

@KZARCA, could you post your right docker-compose.yml ? Thanks.

There were several problems with my docker-compose file, here is the working one.

version: "3"
services:
  reverseproxy:
    container_name: reverseproxy
    build:
      context: .
      dockerfile: reverse.Dockerfile
    ports:
      - 80:80
    restart: always

  shinyproxy:
      build:
        context: .
        dockerfile: shinyProxy.Dockerfile
      depends_on:
        - reverseproxy
      container_name: shinyproxy
      volumes:
        - /var/run/docker.sock:/var/run/docker.sock

networks:
  default:
      external:
        name: sp-example-net