caddy: caddy reload command returns successfully but does not work
Environement
- Podman
- Image: Caddy-2.7.2-alpine
Step to reproduce
- Create Caddyfile :
http://localhost
respond "Hello World"
- Create container :
podman run -d \
-v path/to/Caddyfile:/etc/caddy/Caddyfile:ro \
-v /srv:/srv:ro \
-v caddy_data:/data \
-v caddy_config:/config \
-p 80:80 \
--name caddy docker.io/caddy-alpine
- run
curl localhost, outputHello World - Modify Caddyfile’s respond line to
respond "Goodbye World" - Run
podman exec -w /etc/caddy caddy caddy reload curl localhost, outputHello Worldinstead ofGoodbye World
Workaround
Restart the container with podman restart caddy
Log Output after run caddy reload
{"level":"info","ts":1691840974.3116052,"logger":"admin.api","msg":"received request","method":"POST","host":"localhost:2019","uri":"/load","remote_ip":"127.0.0.1","remote_port":"54268","headers":{"Accept-Encoding":["gzip"],"Content-Length":["230"],"Content-Type":["application/json"],"Origin":["http://localhost:2019"],"User-Agent":["Go-http-client/1.1"]}}
{"level":"info","ts":1691840974.3117096,"msg":"config is unchanged"} # <-- Seems that it does not detect the value of respond changed
{"level":"info","ts":1691840974.311715,"logger":"admin.api","msg":"load complete"}
Also Tried
Seeing the log output, I think maybe it does not detect a change of the value in respond. So I tried adding a new directive, but it still does not work. Furthermore, the log output still say config is unchanged
- Edit
Caddyfileand addheader Custom-Header "My value" - Run
podman exec -w /etc/caddy caddy caddy reload - Run
curl -v localhost, I should see the newly added header in the response but it’s not there
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (4 by maintainers)
@emilylange, impressive !
ls -ifrom both outside and inside container -> the inode numbers are equalsls -i-> the inode numbers are different. Andcatfrom inside of the container does not output latest fileI’ve googled a bit, I managed to fix the issue using the solution in this Stackoverflow’s post
Caddyfileto a new subdirectory on hostpath/to/subdir/containing/Caddyfileto/etc/caddyAs the issue is related to the docker/podman itself, you may close this issue. You may also update the
Graceful reloadsparagraph on Docker Hub according to the fix I written above.I know this was closed, but the proper solution/explanation/reasoning(?) is not here yet, i think.
This behavior isn’t actually a bug in docker or podman, it’s a consequence of backupcopy=auto in vim (default almost everywhere), the “edited” file is actually a new file that’s been just renamed to the original file’s name, the bind mount is still (correctly) pointing to the old file’s inode. If you want to actually change the file in place, you have to use “backupcopy=yes”, this can be set in vim with “:set backupcopy=yes” in vim or in .vimrc with “set backupcopy=yes”. If you use a different editor and see this behavior, it’s the same case, just find out how to reconfigure your editor.
Bind mounting a directory is a workaround, it doesn’t address the cause.
TL;DR: use “:set backupcopy=yes” in vim or “set backupcopy” in .vimrc
Pretty sure, that’s due to how podman/docker handle bind mounts.
You should be able to compare the inode numbers with
ls -ibefore and after your change made to the Caddyfile and then see how the inodes are no longer in sync.@polarathene right, thanks for the correction
This issue is Aug 2023, yours was Aug 2024 🤔