Mulitple Docker Containers on Port 80 with Same Domain Mulitple Docker Containers on Port 80 with Same Domain docker docker

Mulitple Docker Containers on Port 80 with Same Domain


I solved this issue with an nginx reverse proxy.

Here's the Dockerfile for the nginx container:

FROM nginxCOPY nginx.conf /etc/nginx/nginx.conf

And this is the nginx.conf:

http {        server {              listen 80;              location / {                proxy_pass http://app1:5001/;              }              location /api/ {                proxy_pass http://app2:5000/api/;              }        }}

I then stood up the nginx, app1, and app2 containers inside the same docker network.

Make sure to include the trailing / in the location and proxy paths, otherwise nginx will return a '502: Bad Gateway'.

All requests go through the docker host on port 80, which hands them off to the nginx container, which then forwards them onto the app containers based on the url path.