1. Caddy version:
v2.6.3 h1:QRVBNIqfpqZ1eJacY44I6eUC1OcxQ8D04EKImzpj7S8=
2. How I installed, and run Caddy:
a. System environment:
Docker
b. Command:
docker-compose up
c. Service/unit/compose file:
version: "3.8"
services:
go:
build: ./
ports:
- "3000"
volumes:
- ./:/telos
caddy:
image: caddy:latest
ports:
- "2080:80"
- "2015:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- ./tmp/caddy/pki:/data/caddy/pki
- ./public:/public
d. My complete Caddy config:
:2015 {
encode zstd gzip
log
handle /api/* {
reverse_proxy localhost:3000
}
handle {
root * public
try_files {path} index.html
file_server
}
}
e. My complete Dockerfile:
FROM golang:1.19
WORKDIR /telos
ADD public /public
RUN go install github.com/cosmtrek/air@latest
COPY go.mod ./
RUN go mod download
CMD ["air", "-c", ".air.toml"]
3. The problem I’m having:
Howdy! I’m new to Caddy and Docker and I researched as best as I could. I have a Go server/api that works fine but want to take advantage of Caddy’s full-featured server and automatic HTTPS capability. I created the Caddyfile included here and everything works great. However it would be nice if I could bundle everything up for team members and take advantage of live Go rebuilding so I started with the linked resource which was written for some Linux variant I suppose as it offers this command as a way to get Caddy to trust certificates: XDG_DATA_HOME=$(pwd)/tmp caddy trust
something that Windows doesn’t understand. I have seen many replies from @ francislavoie that say there is no automatic way to get Caddy and Docker to handle this trust issue and if so I can just walk away and tell my team that Docker can’t be involved in the development of this project.
At this point I have 2 problems:
- Caddy won’t even serve a non-HTTPS version of the site. As you can see I both copy the static file folder using
ADD
in theDockerfile
and include./public:/public
in mydocker-compose.yml
but browsing tohttp://localhost:2080/
results in this error page:
This page isn’t working
localhost didn’t send any data.
ERR_EMPTY_RESPONSE
- Once I get Caddy in Docker to serve my files, I don’t know how to handle the HTTPS situation. I’d prefer something automatic but if I have to tell my team to copy some files to some place I need to know what and where.
4. Error messages and/or full log output:
2023-02-11 00:26:33 {"level":"info","ts":1676093193.210777,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
2023-02-11 00:26:33 {"level":"info","ts":1676093193.2168117,"logger":"admin","msg":"admin endpoint started","address":"localhost:2019","enforce_origin":false,"origins":["//localhost:2019","//[::1]:2019","//127.0.0.1:2019"]}
2023-02-11 00:26:33 {"level":"info","ts":1676093193.2213476,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc000033180"}
2023-02-11 00:26:33 {"level":"info","ts":1676093193.2218623,"logger":"tls","msg":"cleaning storage unit","description":"FileStorage:/data/caddy"}
2023-02-11 00:26:33 {"level":"info","ts":1676093193.2218924,"logger":"http.log","msg":"server running","name":"srv0","protocols":["h1","h2","h3"]}
2023-02-11 00:26:33 {"level":"info","ts":1676093193.2219105,"logger":"tls","msg":"finished cleaning storage units"}
2023-02-11 00:26:33 {"level":"info","ts":1676093193.2259758,"msg":"autosaved config (load with --resume flag)","file":"/config/caddy/autosave.json"}
2023-02-11 00:26:33 {"level":"info","ts":1676093193.2260005,"msg":"serving initial configuration"}
2023-02-11 00:28:05 {"level":"info","ts":1676093285.5991693,"msg":"shutting down apps, then terminating","signal":"SIGTERM"}
2023-02-11 00:28:05 {"level":"warn","ts":1676093285.599221,"msg":"exiting; byeee!! đź‘‹","signal":"SIGTERM"}
2023-02-11 00:28:05 {"level":"info","ts":1676093285.600214,"logger":"tls.cache.maintenance","msg":"stopped background certificate maintenance","cache":"0xc000033180"}
2023-02-11 00:28:05 {"level":"info","ts":1676093285.6004004,"logger":"admin","msg":"stopped previous server","address":"localhost:2019"}
2023-02-11 00:28:05 {"level":"info","ts":1676093285.600463,"msg":"shutdown complete","signal":"SIGTERM","exit_code":0}
2023-02-11 00:28:13 {"level":"info","ts":1676093293.152982,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
2023-02-11 00:28:13 {"level":"info","ts":1676093293.15863,"logger":"admin","msg":"admin endpoint started","address":"localhost:2019","enforce_origin":false,"origins":["//localhost:2019","//[::1]:2019","//127.0.0.1:2019"]}
2023-02-11 00:28:13 {"level":"info","ts":1676093293.1634111,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc0003fec40"}
2023-02-11 00:28:13 {"level":"info","ts":1676093293.165817,"logger":"http.log","msg":"server running","name":"srv0","protocols":["h1","h2","h3"]}
2023-02-11 00:28:13 {"level":"info","ts":1676093293.1658442,"logger":"tls","msg":"cleaning storage unit","description":"FileStorage:/data/caddy"}
2023-02-11 00:28:13 {"level":"info","ts":1676093293.1658866,"logger":"tls","msg":"finished cleaning storage units"}
2023-02-11 00:28:13 {"level":"info","ts":1676093293.1661632,"msg":"autosaved config (load with --resume flag)","file":"/config/caddy/autosave.json"}
2023-02-11 00:28:13 {"level":"info","ts":1676093293.1661751,"msg":"serving initial configuration"}
2023-02-11 00:29:23 {"level":"info","ts":1676093363.8447692,"msg":"shutting down apps, then terminating","signal":"SIGTERM"}
2023-02-11 00:29:23 {"level":"warn","ts":1676093363.8447964,"msg":"exiting; byeee!! đź‘‹","signal":"SIGTERM"}
2023-02-11 00:29:23 {"level":"info","ts":1676093363.8458045,"logger":"tls.cache.maintenance","msg":"stopped background certificate maintenance","cache":"0xc0003fec40"}
2023-02-11 00:29:23 {"level":"info","ts":1676093363.8458636,"logger":"admin","msg":"stopped previous server","address":"localhost:2019"}
2023-02-11 00:29:23 {"level":"info","ts":1676093363.8458705,"msg":"shutdown complete","signal":"SIGTERM","exit_code":0}
2023-02-11 00:30:06 {"level":"info","ts":1676093406.8709257,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
2023-02-11 00:30:06 {"level":"info","ts":1676093406.8780737,"logger":"admin","msg":"admin endpoint started","address":"localhost:2019","enforce_origin":false,"origins":["//[::1]:2019","//127.0.0.1:2019","//localhost:2019"]}
2023-02-11 00:30:06 {"level":"info","ts":1676093406.8811905,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc0000f4d20"}
2023-02-11 00:30:06 {"level":"info","ts":1676093406.8816216,"logger":"tls","msg":"cleaning storage unit","description":"FileStorage:/data/caddy"}
2023-02-11 00:30:06 {"level":"info","ts":1676093406.8818042,"logger":"tls","msg":"finished cleaning storage units"}
2023-02-11 00:30:06 {"level":"info","ts":1676093406.8816645,"logger":"http.log","msg":"server running","name":"srv0","protocols":["h1","h2","h3"]}
2023-02-11 00:30:06 {"level":"info","ts":1676093406.8848062,"msg":"autosaved config (load with --resume flag)","file":"/config/caddy/autosave.json"}
2023-02-11 00:30:06 {"level":"info","ts":1676093406.8849547,"msg":"serving initial configuration"}
2023-02-11 00:31:09 {"level":"info","ts":1676093469.900885,"msg":"shutting down apps, then terminating","signal":"SIGTERM"}
2023-02-11 00:31:09 {"level":"warn","ts":1676093469.900938,"msg":"exiting; byeee!! đź‘‹","signal":"SIGTERM"}
2023-02-11 00:31:09 {"level":"info","ts":1676093469.9018898,"logger":"tls.cache.maintenance","msg":"stopped background certificate maintenance","cache":"0xc0000f4d20"}
2023-02-11 00:31:09 {"level":"info","ts":1676093469.9020283,"logger":"admin","msg":"stopped previous server","address":"localhost:2019"}
2023-02-11 00:31:09 {"level":"info","ts":1676093469.9020677,"msg":"shutdown complete","signal":"SIGTERM","exit_code":0}
2023-02-11 00:42:14 {"level":"info","ts":1676094134.6171691,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
2023-02-11 00:42:14 {"level":"info","ts":1676094134.6218672,"logger":"admin","msg":"admin endpoint started","address":"localhost:2019","enforce_origin":false,"origins":["//localhost:2019","//[::1]:2019","//127.0.0.1:2019"]}
2023-02-11 00:42:14 {"level":"info","ts":1676094134.6225202,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc0002b8a10"}
2023-02-11 00:42:14 {"level":"info","ts":1676094134.6229713,"logger":"http.log","msg":"server running","name":"srv0","protocols":["h1","h2","h3"]}
2023-02-11 00:42:14 {"level":"info","ts":1676094134.6230016,"logger":"tls","msg":"cleaning storage unit","description":"FileStorage:/data/caddy"}
2023-02-11 00:42:14 {"level":"info","ts":1676094134.6230485,"logger":"tls","msg":"finished cleaning storage units"}
2023-02-11 00:42:14 {"level":"info","ts":1676094134.623403,"msg":"autosaved config (load with --resume flag)","file":"/config/caddy/autosave.json"}
2023-02-11 00:42:14 {"level":"info","ts":1676094134.6234171,"msg":"serving initial configuration"}
5. What I already tried:
Other than searching this site and other support communities, nothing. Caddy runs fine with this configuration under Windows, but fails under Docker, and I have no idea what those logs mean.