Why does the zot
image use the VOLUME
instruction?
#3020
Replies: 2 comments 8 replies
-
I am not sure of the original reason for using a volume in the dockerfile itself, but in general a volume should be used in order to persist the data. In any case I am 99% sure there is no use case to run the image without specifying a volume when starting a container. I don't know where this message is now, it clear in the readme updated in https://github.com/project-zot/zot/pull/64/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R68 It's not just the trivy data which is store there, there's also the images (if local storage is used), image metadata (if boltdb is used as opposed to dynamodb/redis), UI sessions, and possibly other data which is escaping me. |
Beta Was this translation helpful? Give feedback.
-
This sounds like it begs a PR ... pls submit one. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I assume this is the Stacker equivalent of declaring
VOLUME
? (Dockerfile
equivalent for reference):zot/build/stacker.yaml
Lines 75 to 76 in d465690
TL;DR: Rarely makes any sense or does any good. This instruction is typically legacy unless you have a valid use-case to warrant it. Given the PRs that introduced both lines, it seems evident that this is not the case.
This creates an implicit anonymous volume when creating the container. If you were to destroy the container after stopping it (
docker run --rm
), the volume would be deleted as well. In the past before other volume types were supported by Docker leveragingVOLUME
had some advantages including with performance, but the default storage driver today is much better in that regard AFAIK.Thus I usually encounter
VOLUME
as a decision not well understood by the image author. Or they rely on Docker Compose behaviour which differs. Docker Compose will tie the anonymous volume to the associated service.zot
toharbor
, and provided both images declareVOLUME
to the same path, that anonymous volume will persist to the container using a different image (but still for the same Docker Compose service).VOLUME
, you can provide an explicit anonymous volume mount in thecompose.yaml
and again it'll not be a fresh one, it's keyed by path and service, so it'll represent the same data.docker compose down
and similar commands that destroy the container won't remove the implicit volume. This can be a bit surprising when the user expects an ephemeral image to be immutable and result in a clean slate when there are no explicit persistence configured. That would be the case with Docker CLI, but as mentioned with Docker Compose this behaviour can be a little unexpected.For reference
docker compose down --volumes
(destroy the anonymous volumes with containers) ordocker compose up --force-recreate --renew-anon-volumes
(keeps the old one on disk, attaches a blank anonymous volume to the newly created container) and similar commands can be used to workaround that. Alternative container engines differ, like Podman which has config support to changeVOLUME
to ephemeral tmpfs mounts or ignore mounting a volume completely.Rarely should an image need to declare
VOLUME
, especially if it can result in 1.7GB of data each time one of these are created implicitly (the mainzot
image which defaults toextensions.search.cve
enabling Trivy for vulnerability scanning). If persistence is desired, an explicit volume should be configured.The main perk of the Docker Compose behaviour is to have persistence implicitly that is attached to the Compose service, so that the volume is reattached when the image is upgraded to a new release. While it's rare that the image would change to something completely different under the same service name and just happen to share the same
VOLUME
path, it can happen and that may risk leaking sensitive data unintentionally (and unaware to the typical user). An explicit volume mount avoids all that (or rather more clearly communicates the expectation/behaviour that occurs).For reference:
Dockerfile
originally introducedVOLUME
in 2020: Dockerfile for running zot server #64stacker.yaml
originally introducedvolume
in 2022: Migrate from docker/build-push-action to stacker-build-push-action #499Neither PR has any discussion pertaining to the inclusion of
VOLUME
. Hence I'm inclined it was done so without much thought by the author or concern by the reviewers, rather than with intention to solve any requirements.Beta Was this translation helpful? Give feedback.
All reactions