-
-
Notifications
You must be signed in to change notification settings - Fork 178
Description
I have been scrambling to figure out why my local Docker Compose setup utilizing Caddy as a reverse proxy wasn't working and it all boiled down to a single, simple Caddyfile change (using the internal container port instead of the host port).
Link to relevant docs: https://caddyserver.com/docs/running#docker-compose
Link to forum post coment that gave the proper solution: https://caddy.community/t/caddy-foundry-docker-connection-issues/21265/2
I hope this breakdown helps others who may have been banging their heads against the same problem.
I was under the impression that my Caddyfile should look like:
...
localhost {
reverse_proxy app:3030 <--- <container name>:<host machine port>
}
...
With a Dockerfile like:
caddy:
...
restart: unless-stopped
environment:
- ACME_AGREE=true
volumes:
- /caddy/Caddyfile:/etc/caddy/Caddyfile
- /caddy/site:/srv
- caddy_data:/data
- caddy_config:/config
ports:
- 80:80
- 443:443
- 443:443/udp
depends_on:
- app
app:
...
container_name: app
ports:
- 3030:3000
restart: unless-stopped
But that just resulted in my app being unreachable. In reality all I needed was to utilize the internal container port that was being used by the app.
So my Dockerfile could look like:
caddy:
...
restart: unless-stopped
environment:
- ACME_AGREE=true
volumes:
- /caddy/Caddyfile:/etc/caddy/Caddyfile
- /caddy/site:/srv
- caddy_data:/data
- caddy_config:/config
ports:
- 80:80
- 443:443
- 443:443/udp
depends_on:
- app
app:
...
container_name: app
### Don't even need to bind ports
# ports:
# - 3030:3000
restart: unless-stopped
With a Caddyfile like:
...
localhost {
reverse_proxy app:3000<--- <container name>:<internal container port>
}
...