This project provides a Dockerized Caddy reverse proxy that dynamically generates its configuration (Caddyfile
) based on mappings defined in the MAPPING
environment variable.
- Dynamic Configuration: The
Caddyfile
is generated at runtime based on theMAPPING
environment variable. - Lightweight: Built on the official Caddy web server image.
- Simple to Use: Configure URL mappings using a single JSON variable.
- Docker installed on your system.
Run the following command to build the Docker image:
docker build -t caddy-reverse-proxy-env-var .
Start a container with your desired mappings:
docker run -d \
--name caddy-reverse-proxy-env-var \
-e MAPPING='[{"example.com":"backend1:8080"},{"api.example.com":"backend2:9090"}]' \
-p 80:80 \
caddy-reverse-proxy-env-var
Add http
if you want to disable https redirect
docker run -d \
--name caddy-reverse-proxy-env-var \
-e MAPPING='[{"http://example.com":"backend1:8080"},{"http://api.example.com":"backend2:9090"}]' \
-p 80:80 \
caddy-reverse-proxy-env-var
The MAPPING
environment variable should be a JSON array of objects, where each object maps a source URL to a target address. Example:
[
{"example.com": "backend1:8080"},
{"api.example.com": "backend2:9090"}
]
To verify the configuration, check the container logs for the generated Caddyfile
:
docker logs caddy-reverse-proxy-env-var
Stop and remove the container when it is no longer needed:
docker stop caddy-reverse-proxy-env-var
docker rm caddy-reverse-proxy-env-var
You can pull the prebuilt image from Docker Hub:
https://hub.docker.com/repository/docker/lenny4/caddy-reverse-proxy-env-var/general
To use the image from Docker Hub:
docker pull lenny4/caddy-reverse-proxy-env-var
This project is licensed under the MIT License. Contributions are welcome!