caddy: caddy reload command returns successfully but does not work

Environement

  • Podman
  • Image: Caddy-2.7.2-alpine

Step to reproduce

  1. Create Caddyfile :
http://localhost
respond "Hello World"
  1. 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
  1. run curl localhost, output Hello World
  2. Modify Caddyfile’s respond line to respond "Goodbye World"
  3. Run podman exec -w /etc/caddy caddy caddy reload
  4. curl localhost, output Hello World instead of Goodbye 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

  1. Edit Caddyfile and add header Custom-Header "My value"
  2. Run podman exec -w /etc/caddy caddy caddy reload
  3. 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)

Most upvoted comments

@emilylange, impressive !

  1. Restart the container
  2. Check with ls -i from both outside and inside container -> the inode numbers are equals
  3. make a change to Caddyfile from outside of the container.
  4. Check again with ls -i -> the inode numbers are different. And cat from inside of the container does not output latest file

I’ve googled a bit, I managed to fix the issue using the solution in this Stackoverflow’s post

  1. Move Caddyfile to a new subdirectory on host
  2. Recreate container with a bind mount from path/to/subdir/containing/Caddyfile to /etc/caddy
  3. Now you should be able to modify Caddyfile while container is running

As the issue is related to the docker/podman itself, you may close this issue. You may also update the Graceful reloads paragraph 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 -i before 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

which predates this one

This issue is Aug 2023, yours was Aug 2024 🤔