Preflight checklist
Describe your problem
Some of the Dockerfile files in this repo use the VOLUME instruction: https://github.com/ory/hydra/tree/master/.docker
Dockerfile references
|
# By creating the sqlite folder as the ory user, the mounted volume will be owned by ory:ory, which |
|
# is required for read/write of SQLite. |
|
RUN mkdir -p /var/lib/sqlite && \ |
|
chown ory:ory /var/lib/sqlite |
|
|
|
VOLUME /var/lib/sqlite |
|
|
|
# Exposing the ory home directory |
|
VOLUME /home/ory |
|
# By creating the sqlite folder as the ory user, the mounted volume will be owned by ory:ory, which |
|
# is required for read/write of SQLite. |
|
RUN mkdir -p /var/lib/sqlite && \ |
|
chown ory:ory /var/lib/sqlite |
|
|
|
VOLUME /var/lib/sqlite |
|
|
|
# Exposing the ory home directory |
|
VOLUME /home/ory |
PR that introduced VOLUME: #2129
VOLUME is not necessary:
- A container will persist it's internal state until it's destroyed (
docker rm container_name, docker run --rm, docker compose down, etc). An anonymous volume is often mistakenly added despite being redundant.
- An implicit anonymous volume copies data from the image to the host per container instance created. This is wasteful and accumulates over runs.
- When persistence via a volume is actually necessary, it should be explicit (
docker run --volume ./host/path/:container/path, or the volume key in compose.yaml, etc).
- Anonymous (
-v container/path):
I want to persist the volume without a human-friendly name to reference
- Named (
-v my_data:container/path):
I want a human-friendly name, but not easy access from the host filesystem, just persist my data externally from the container
- Bind mount (
-v host/path:container/path):
I want to persist the data at a known location on the host filesystem that I can easily access directly
I also provided justification in 2022 for Caddy to do the same, citing various sources from other popular official images that likewise dropped VOLUME (which is effectively a legacy feature that causes more problems implicitly than benefits).
Describe your ideal solution
Remove VOLUME from the Dockerfile lines referenced (this would be applicable to other Ory projects too).
Workarounds or alternatives
- The redundant copy can be avoided.. if the user provides their own bind mount to the same mount point at runtime (anonymous & named volumes copy container content by default, bind mounts replace).
- Alternatively, the
--rm option will remove the container on exit, additionally discarding the implicitly created anonymous volume. This doesn't prevent writing a copy of the volume data to disk, which if large slows startup.
Ideally though, without a real reason to keep VOLUME, it should just be removed from the Dockerfiles? 🤷♂️
Version
2.1.2
Preflight checklist
Describe your problem
Some of the
Dockerfilefiles in this repo use theVOLUMEinstruction: https://github.com/ory/hydra/tree/master/.dockerDockerfile references
hydra/.docker/Dockerfile-build
Line 27 in f9cee32
hydra/.docker/Dockerfile-hsm
Lines 54 to 62 in f9cee32
hydra/.docker/Dockerfile-sqlite
Lines 19 to 27 in f9cee32
PR that introduced
VOLUME: #2129VOLUMEis not necessary:docker rm container_name,docker run --rm,docker compose down, etc). An anonymous volume is often mistakenly added despite being redundant.docker run --volume ./host/path/:container/path, or thevolumekey incompose.yaml, etc).-v container/path):-v my_data:container/path):-v host/path:container/path):I also provided justification in 2022 for Caddy to do the same, citing various sources from other popular official images that likewise dropped
VOLUME(which is effectively a legacy feature that causes more problems implicitly than benefits).Describe your ideal solution
Remove
VOLUMEfrom theDockerfilelines referenced (this would be applicable to other Ory projects too).Workarounds or alternatives
--rmoption will remove the container on exit, additionally discarding the implicitly created anonymous volume. This doesn't prevent writing a copy of the volume data to disk, which if large slows startup.Ideally though, without a real reason to keep
VOLUME, it should just be removed from theDockerfiles? 🤷♂️Version
2.1.2