1. Caddy version (caddy version
):
Latest (pull by docker)
2. How I run Caddy:
I run caddy via docker. When I do so with the setup to serve a single file all is good. When I use a Caddy file the results are empty"
A. This way works fine
echo "Hello world" > index.html
docker run -p 80:80 -v $PWD/index.html:/usr/share/caddy/index.html caddy
In another terminal
curl -v http://localhost/
B. This second way with a Caddyfile returns curl: (52) Empty reply from server
docker run -p 80:80 -v $PWD/Caddyfile:/etc/caddy/Caddyfile caddy
Caddyfile
{
auto_https off
}
localhost
respond "Hello, world!"
a. System environment:
Docker version : Docker version 19.03.12, build 48a66213fe
Mac 10.13.6
Docker application is configured to access the local working directory. Docker … Preferences … Resources … File Sharing … add local directory and restart.
b. Command:
See #2 above
c. Service/unit/compose file:
NA
d. My complete Caddyfile or JSON config:
See above
3. The problem I’m having:
When docker runs caddy with a simple file it works. When I switch to using a simple docker file it does not.
4. Error messages and/or full log output:
Working version:
/r/dev/npuser/temp$ docker run -p 80:80 -v $PWD/index.html:/usr/share/caddy/index.html caddy
{"level":"info","ts":1601583133.332981,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
{"level":"info","ts":1601583133.3369324,"logger":"admin","msg":"admin endpoint started","address":"tcp/localhost:2019","enforce_origin":false,"origins":["localhost:2019","[::1]:2019","127.0.0.1:2019"]}
{"level":"info","ts":1601583133.338265,"logger":"http","msg":"server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server","server_name":"srv0","http_port":80}
{"level":"info","ts":1601583133.3388834,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc000308930"}
{"level":"info","ts":1601583133.3407876,"logger":"tls","msg":"cleaned up storage units"}
{"level":"info","ts":1601583133.3423831,"msg":"autosaved config","file":"/config/caddy/autosave.json"}
{"level":"info","ts":1601583133.3430257,"msg":"serving initial configuration"}
/r/dev/npuser/temp$ curl -v http://localhost/
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 80 (#0)
> GET / HTTP/1.1
> Host: localhost
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Accept-Ranges: bytes
< Content-Length: 12
< Content-Type: text/html; charset=utf-8
< Etag: "qhjfccc"
< Last-Modified: Thu, 01 Oct 2020 19:26:36 GMT
< Server: Caddy
< Date: Thu, 01 Oct 2020 20:12:20 GMT
<
hello world
* Connection #0 to host localhost left intact
Non working version
/r/dev/npuser/temp$ docker run -p 80:80 -v $PWD/Caddyfile:/etc/caddy/Caddyfile caddy
{"level":"info","ts":1601583225.4984696,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
{"level":"info","ts":1601583225.5005987,"logger":"admin","msg":"admin endpoint started","address":"tcp/localhost:2019","enforce_origin":false,"origins":["localhost:2019","[::1]:2019","127.0.0.1:2019"]}
{"level":"info","ts":1601583225.5013092,"msg":"autosaved config","file":"/config/caddy/autosave.json"}
{"level":"info","ts":1601583225.501362,"msg":"serving initial configuration"}
{"level":"info","ts":1601583225.5018826,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc000226ee0"}
{"level":"info","ts":1601583225.5020576,"logger":"tls","msg":"cleaned up storage units"}
/r/dev/npuser/temp$ curl -v http://localhost/
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 80 (#0)
> GET / HTTP/1.1
> Host: localhost
> User-Agent: curl/7.54.0
> Accept: */*
>
* Empty reply from server
* Connection #0 to host localhost left intact
curl: (52) Empty reply from server
5. What I already tried:
The above is a major reduction from my main application configuration. I’m will be using docker compose with reverse proxy and static Vue web site.
I also tried without the global disable TLS but that just makes local requests redirect to https which fails because there are no certs for localhost. This caddy file
localhost
respond "Hello, world!"
Gets the following logs from using the following curl commands
/r/dev/npuser/temp$ docker run -p 80:80 -v $PWD/Caddyfile:/etc/caddy/Caddyfile caddy
{"level":"info","ts":1601583510.320734,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
{"level":"info","ts":1601583510.3239393,"logger":"admin","msg":"admin endpoint started","address":"tcp/localhost:2019","enforce_origin":false,"origins":["localhost:2019","[::1]:2019","127.0.0.1:2019"]}
{"level":"info","ts":1601583510.3247647,"logger":"http","msg":"server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS","server_name":"srv0","https_port":443}
{"level":"info","ts":1601583510.3256257,"logger":"http","msg":"enabling automatic HTTP->HTTPS redirects","server_name":"srv0"}
{"level":"info","ts":1601583510.3291945,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc0002da850"}
{"level":"info","ts":1601583510.3399036,"logger":"tls","msg":"setting internal issuer for automation policy that has only internal subjects but no issuer configured","subjects":["localhost"]}
{"level":"info","ts":1601583510.3410902,"logger":"tls","msg":"cleaned up storage units"}
{"level":"warn","ts":1601583510.400767,"logger":"pki.ca.local","msg":"installing root certificate (you might be prompted for password)","path":"storage:pki/authorities/local/root.crt"}
2020/10/01 20:18:30 Warning: "certutil" is not available, install "certutil" with "apt install libnss3-tools" or "yum install nss-tools" and try again
2020/10/01 20:18:30 define JAVA_HOME environment variable to use the Java trust
2020/10/01 20:18:30 certificate installed properly in linux trusts
{"level":"info","ts":1601583510.439247,"logger":"http","msg":"enabling automatic TLS certificate management","domains":["localhost"]}
{"level":"info","ts":1601583510.4404404,"msg":"autosaved config","file":"/config/caddy/autosave.json"}
{"level":"info","ts":1601583510.4420805,"msg":"serving initial configuration"}
{"level":"info","ts":1601583510.4417844,"logger":"tls.obtain","msg":"acquiring lock","identifier":"localhost"}
{"level":"info","ts":1601583510.4436636,"logger":"tls.obtain","msg":"lock acquired","identifier":"localhost"}
{"level":"info","ts":1601583510.4489083,"logger":"tls.obtain","msg":"certificate obtained successfully","identifier":"localhost"}
{"level":"info","ts":1601583510.4493704,"logger":"tls.obtain","msg":"releasing lock","identifier":"localhost"}
{"level":"warn","ts":1601583510.4509451,"logger":"tls","msg":"stapling OCSP","error":"no OCSP stapling for [localhost]: no OCSP server specified in certificate"}
With:
/r/dev/npuser/temp$ curl -v http://localhost/
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 80 (#0)
> GET / HTTP/1.1
> Host: localhost
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 308 Permanent Redirect
< Connection: close
< Location: https://localhost/
< Server: Caddy
< Date: Thu, 01 Oct 2020 20:18:54 GMT
< Content-Length: 0
<
* Closing connection 0
/r/dev/npuser/temp$ curl -v https://localhost/
* Trying ::1...
* TCP_NODELAY set
* Connection failed
* connect to ::1 port 443 failed: Connection refused
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connection failed
* connect to 127.0.0.1 port 443 failed: Connection refused
* Failed to connect to localhost port 443: Connection refused
* Closing connection 0
curl: (7) Failed to connect to localhost port 443: Connection refused