Overview • Prerequisites • Quick start • DNS setup • Use with your apps • Docker run example • Included services
Simple setup for jwilder/nginx-proxy with Let's Encrypt companion. It automatically routes requests based on hostnames and can provision certificates via ACME.
- Docker and Docker Compose
- An external Docker network named
webthat your apps join:
docker network create webBring up the proxy and ACME companion:
docker compose up -dThis stack exposes ports 80 and 443 and listens for containers on the web network.
Attach your containers to the same web network and set the environment variables below.
To route any subdomain of example.com through this proxy, create a wildcard DNS record pointing to this server's public IP.
- Create an A (or AAAA) record for
*.example.comto your server's IP address. - Optional: also point
example.comto the same IP if you want the apex domain served.
Notes:
- A wildcard DNS record does not automatically create a wildcard TLS certificate. Certificates are issued per hostname unless you configure DNS-01 with a supported DNS provider.
- If you don't want a wildcard, you can instead create individual A/AAAA records (e.g.,
app1.example.com,app2.example.com).
- VIRTUAL_HOST: Comma-separated hostnames to route to this container (e.g.,
app.example.com). - LETSENCRYPT_HOST: Hostname(s) for which to request TLS certificates. Typically the same as
VIRTUAL_HOST. - LETSENCRYPT_EMAIL (optional): Email used for ACME registration and renewal notices.
- HOST_PORT (optional): Port your app listens on inside the container. If omitted, the proxy detects the port automatically from
EXPOSEorports.
services:
whoami:
image: traefik/whoami
container_name: whoami
restart: always
expose:
- "80" # alternatively, publish and set HOST_PORT
environment:
- VIRTUAL_HOST=example.com
- LETSENCRYPT_HOST=example.com
- LETSENCRYPT_EMAIL=you@example.com # optional
# - HOST_PORT=80 # optional; auto-detected if omitted
networks:
- web
networks:
web:
external: trueNotes:
- Use
exposeto make the internal port visible to the proxy without publishing it on the host. If you instead publish withports,HOST_PORTis typically unnecessary because the proxy will detect the exposed/published port. - Ensure your DNS records point to the server running this proxy.
If you prefer docker run, here's an example using all supported env variables for an app container (not the proxy):
# Create the external network once
docker network create web
# Run your application container
docker run -d \
--name whoami \
--restart always \
--expose 80 \
-e VIRTUAL_HOST=example.com \
-e LETSENCRYPT_HOST=example.com \
-e LETSENCRYPT_EMAIL=you@example.com \ # optional
-e HOST_PORT=80 \ # optional; auto-detected if omitted
--network web \
traefik/whoamiNotes:
- Replace
example.comand the email with your domain and contact.
This repository's docker-compose.yml defines:
nginx-proxy(listens on 80/443)nginx-proxy-acmecompanion (obtains and renews certificates)
Both services join the external web network.