Hey everyone! I have a problem with call caddy API via docker-compose hostnames (servicename), I have added config to Caddyfile for exposing caddy API on 0.0.0.0:2019 IP, but still can’t connect from another container in the same docker network like “curl http://caddy:2019/config/ | jq”
Welcome Myron –
Can you please fill out the help template so we can help you?
1. Caddy version (caddy version
):
v2.3.0 h1:fnrqJLa3G5vfxcxmOH/+kJOcunPLhSBnjgIvjXV/QTA=
2. How I run Caddy:
Caddy is running on docker container (docker-compose)
a. System environment:
Docker version 20.10.3, build 48d30b5
b. Command:
I use docker-compose command
c. Service/unit/compose file:
caddy:
image: caddy:latest
restart: unless-stopped
ports:
- "80:80"
- "443:443"
expose:
- 2019
volumes:
- /root/Caddyfile:/etc/caddy/Caddyfile
- /root/.caddy/:/data
- caddy_config:/config
network_mode: bridge
volumes:
caddy_config:
d. My complete Caddyfile or JSON config:
{
admin 0.0.0.0:2019 {
}
}
frontend.domain.com {
reverse_proxy * http://frontend:9006 {
}
}
backend.domain.com {
reverse_proxy * http://backend:9005 {
}
}
3. The problem I’m having:
I deploy caddy with my 2 containers, that have to connect to caddy API, for generation subdomains for users, but the backend can’t connect to caddy API via docker-compose service names, I’m getting an error like curl: (6) Could not resolve host: caddy, but if I try to curl from caddy container to backend I’m getting 200 response via curl http://backend:9005/
4. Error messages and/or full log output:
curl: (6) Could not resolve host: caddy
5. What I already tried:
I tried to connect through the hostname hash of the caddy container and got a response of 200, but in my opinion, it is not convenient to look for a hostname hash every time and connect through it
6. Links to relevant resources:
That’s strange. Maybe if you specify container_name:
, Docker’s DNS will resolve that hostname?
Ultimately that’s a Docker issue rather than a Caddy issue. I’ve not had that problem before, so I don’t know what the cause could be.
Yea, u were right, have to specify container_name:
, then calls with hostname works, but it’s so strange. Thnx
This topic was automatically closed after 30 days. New replies are no longer allowed.