Creating a Minimal Reverse Proxy with Docker [Memo]

2025-06-07

Introduction

This is a tutorial for a configuration I plan to build later.
I'm a beginner with Docker and documenting this as part of my learning process, so the content may be incomplete.

Environment

  • Host: Ubuntu 24.04

Architecture

We’ll create a reverse proxy and web container in the same network,
and configure it so that port 8080 forwards to port 80 of webapp01.

Reverse proxy with Docker

Directories

  • Create the root directory for the Docker project:
    /home/docker/

  • Create directories for the reverse proxy and webapp01:
    /home/docker/reverse-proxy
    /home/docker/webapp01

Creating the Setup

Goal: Accessing localhost:8080 should display the web page from webapp01.

Create Docker Network

Use the command below to create a Docker network.
Normally, you’d specify subnet, gateway, etc., but we’ll omit those for this minimal example.

docker network create reverse-proxy-network

Nginx Config for Reverse Proxy

Create the config file at:
/home/docker/reverse-proxy/conf.d/reverse-proxy.conf

Any .conf file in conf.d will be automatically loaded.

server {
    listen 80;
    server_name webapp01;
    location / {
        proxy_pass http://webapp01:80/;
    }
}

listen specifies the IP/port to receive requests (here: all IPv4 on port 80).
The location directive forwards requests — for now, it's minimal and does not include headers, timeouts, or SSL settings.

Reverse Proxy Service

Create a docker-compose file at:
/home/docker/reverse-proxy/docker-compose.yml

services:
  reverse-proxy:
    image: nginx:alpine
    ports:
      - "8080:80"
    volumes:
      - ./conf.d:/etc/nginx/conf.d
    networks:
      - reverse-proxy-network

networks:
  reverse-proxy-network:
    external: true

This uses the lightweight nginx:alpine image.
Host port 8080 maps to container port 80.
The config directory is bind-mounted.
We specify an external network we created earlier.

Web Server Content

Create a sample HTML file:
/home/docker/webapp01/public/index.html

Write any content to confirm later via browser or curl.

Web Server Service

Create a docker-compose file at:
/home/docker/webapp01/docker-compose.yml

services:
  webapp01:
    image: nginx:alpine
    volumes:
      - ./public:/usr/share/nginx/html
    networks:
      - reverse-proxy-network

networks:
  reverse-proxy-network:
    external: true

Mount the public folder to the default Nginx web root.
The same reverse-proxy-network is used.

Test the Setup

Start the Containers

Move into each project directory and run:

docker compose -p webapp01 up -d
docker compose -p reverse-proxy up -d

Check with curl

curl http://localhost:8080

If successful, the contents of index.html should be returned.
You can also access via browser using the host's IP address.

Conclusion

We created a very minimal reverse proxy.
Since the config is small, everything built and ran smoothly.

Currently, we’re just forwarding ports.
Next steps include implementing port filtering and practical setups using iptables.

References