caddyserver / caddy-docker

Source for the official Caddy v2 Docker Image
https://hub.docker.com/_/caddy
Apache License 2.0
408 stars 74 forks source link

Caddyfile file bind mount issues #364

Open msladek opened 1 month ago

msladek commented 1 month ago

The current documentation suggests mounting the Caddyfile as a file:

volumes:
  - $PWD/Caddyfile:/etc/caddy/Caddyfile

This approach can lead to issues due to how Docker handles file binds. When an individual file is mounted into a container, Docker mounts the inode of the file on the Linux filesystem. If the file is replaced (which many editors do), the inode changes. Thus it can happen that writes to the file after starting the container won't be reflected between the inside and outside of the container. For more detailed information, refer to this Docker issue: https://github.com/moby/moby/issues/6011

To avoid such issues, it is often suggested mount the parent directory instead of relying on single file bind mounts.

volumes:
  - $PWD/etc:/etc/caddy

with the file tree

├── compose.yml
└── etc
    └── Caddyfile

It would make sense update the documentation accordingly or at least incorporate a warning about this docker issue with file mounts.