This one is going to be short and sweet. Many of you have probably read and/or used the very popular docker nginx-proxy by jwilder. This is not another guide for that. I recommend you read the readme on the linked GitHub for that, or find a different guide.
No, this guide is for proxying non-dockerized services through the same reverse proxy, and the same docker-compose.yml
file. I made a small alpine container just for this purpose. You can find it on GitHub and Docker Hub.
For example, I have a VM running docker, with nginx-proxy performs proxy services for a Ghost blog and Grafana. The file would look something like this:
version: '3'
services:
nginx-proxy:
restart: always
image: jwilder/nginx-proxy:alpine
container_name: nginx-proxy
ports:
- "80:80"
- "443:443"
volumes:
- "/etc/nginx/vhost.d"
- "/usr/share/nginx/html"
- "/var/run/docker.sock:/tmp/docker.sock:ro"
ghost:
image: ghost:latest
restart: always
environment:
url: https://blog.example.com
VIRTUAL_HOST: blog.example.com
grafana:
image: grafana/grafana:latest
restart: always
environment:
VIRTUAL_HOST: monitor.example.com
Now lets say I have a PRTG server running on a separate VM I want to add to the proxy service. You could add the following to the bottom of the docker-compose.yml
file:
...
prtg:
image: soarinferret/iptablesproxy:latest
restart: always
cap_add:
- NET_ADMIN
- NET_RAW
environment:
SERVERIP: 192.168.0.5
SERVERPORT: 80
HOSTPORT: 80
VIRTUAL_HOST: prtg.kanto.cloud
expose:
- '80'
Now after doing running docker-compose up -d
, the new container will spin up, and simply forward all traffic destined to port 80 on the container to port 80 of 192.168.0.5.