1. Caddy version (caddy version
):
5.0.4 Docker Image
2. How I run Caddy:
docker-compose:
version: '3.8'
networks:
intranet:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.16.0.0/24
caddy:
container_name: caddy
image: caddy:5.0.4
user: "0"
restart: always
volumes:
- ./configs/local/Caddyfile:/etc/caddy/Caddyfile
networks:
- intranet
ports:
- "8080:8080"
sysctls:
- net.ipv4.ip_unprivileged_port_start=0
cap_add:
- ALL
myapp:
image: me/myapp:${APP_VERSION}
container_name: myapp
volumes:
- .env/:/.env
networks:
- intranet
expose:
- 8080
entrypoint: './myapp serve'
configs/local/Caddyfile (which is mounted in the caddy container)
{
debug
}
http://localhost:8080 {
reverse_proxy myapp:8080
}
a. System environment:
Windows 11 + WSL running Docker 4.0.3
3. The problem I’m having:
If I do
curl http://localhost:8080/index
I get back HTTP/1.1 502 Bad Gateway
from Server: Caddy
.
If I look at the Caddy logs, I see: unknown network myapp:8080
This makes me think some of the DNS magic with docker is going wrong, and the container name is not pointing to the right IP. HOWEVER, if I exec into the caddy container and do wget myapp:8080
, it works just fine!
4. Error messages and/or full log output:
{"level":"debug","ts":1640056115.1370919,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"myapp:8080/put:80","duration":0.000083086,"request":{"remote_addr":"172.16.0.1:40066","proto":"HTTP/1.1","method":"GET","host":"localhost:8080","uri":"/","headers":{"X-Forwarded-For":["172.16.0.1"],"User-Agent":["curl/7.68.0"],"Accept":["*/*"],"X-Forwarded-Proto":["http"]}},"error":"dial myapp:8080: unknown network myapp:8080"}
{"level":"error","ts":1640056115.137151,"logger":"http.log.error","msg":"dial myapp:8080: unknown network myapp:8080","request":{"remote_addr":"172.16.0.1:40066","proto":"HTTP/1.1","method":"GET","host":"localhost:8080","uri":"/","headers":{"User-Agent":["curl/7.68.0"],"Accept":["*/*"]}},"duration":0.000246772,"status":502,"err_id":"8fnk3ju4y","err_trace":"reverseproxy.statusError (reverseproxy.go:886)"}
5. What I already tried:
exec into caddy container and wget myapp:8080
works. The container name → ip mapping also seems correct. So DNS works but for some reason when used as a reverse proxy it fails?