1. The problem I’m having:
Hello, I’m currently running Caddy 2.7 in a docker compose + Dockerfile combination. When I build the compose, everything installs fine. However, when I run docker compose -f caddy-compose up -d
and check the logs of caddy, it will show caddy exited with code 0
and then restart the container since the container has the property restart: unless-stopped
. I’m not sure why it keeps exiting. I need to use Caddy + Cloudflare because my DNS A record is needed without a cloudflare proxy and CANNOT be used with a Cloudflare proxy and I’m attempting to use a Caddy’s automatic HTTPS feature with Let’s Encrypt with an ACME DNS-01 challenge.
My goal is to automatically have a https certificate that is trusted by the browser and Cloudflare’s Origin Server CA that I manually created isn’t.
2. Error messages and/or full log output:
caddy exited with code 0
No other errors are shown other than this since it repeatedly restarts and exits.
3. Caddy version:
Caddy v2.7-builder
4. How I installed and ran Caddy:
a. System environment:
Ubuntu 22.04
Docker Engine: Built with Docker compose + Dockerfile
b. Command:
docker compose -f caddy-compose.yml build
docker compose -f caddy-compose.yml up -d
docker compose -f caddy-compose.yml logs -f
c. Service/unit/compose file:
caddy-compose.yml
version: "3.7"
services:
caddy:
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
container_name: caddy
ports:
- "80:80"
- "443:443"
- "443:443/udp"
volumes:
- /home/user/homelab/caddy/configs/caddy/Caddyfile:/etc/caddy/Caddyfile
- /home/user/homelab/caddy/configs/caddy/site:/srv
- /home/user/homelab/caddy/configs/caddy/caddy_data:/data
- /home/user/homelab/caddy/configs/caddy/caddy_config:/config
- /etc/ssl:/etc/ssl
networks:
- caddy-network
networks:
caddy-network:
external: true
volumes:
caddy_data:
external: true
caddy_config:
Dockerfile
FROM caddy:2.7-builder AS builder
RUN xcaddy build \
--with github.com/caddy-dns/cloudflare
FROM caddy:2.7-builder
COPY --from=builder /usr/bin/caddy /usr/bin/caddy
d. My complete Caddy config:
Possibly relevant information: The Jellyfin service is connected through caddy with the externally available caddy-network. Domain was originally bought on GoDaddy and changed the name servers so I could use it on Cloudflare. I wasn’t sure if I needed email or not. I have another service running on port 8080, its docker file has the following information:
Complete Caddyfile
ports
- "8080:8080"
{
email example@icloud.com
}
server.exampledomain.com {
tls {
dns cloudflare REDACTED
}
reverse_proxy jellyfin:8096
}
5. Links to relevant resources:
- I tried following the second option, Use Caddy’s automatic HTTPS feature with Let’s Encrypt
Initial Setup was with this Caddy + Docker tutorial video:
Additional docker resources I used to create a custom build:
https://docs.docker.com/compose/compose-file/build/
https://medium.com/analytics-vidhya/how-to-understand-building-images-with-docker-compose-24cbdbc0641f