-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Open
Description
The VOLUME instruction should be removed from the image build.
- Containers already persist state internally until the container is destroyed (for example, an image upgraded to a new tag).
- Proper persistence externally should be explicit.
Lines 16 to 21 in e04913a
| WORKDIR /prometheus | |
| RUN chown -R nobody:nobody /etc/prometheus /prometheus | |
| USER nobody | |
| EXPOSE 9090 | |
| VOLUME [ "/prometheus" ] |
Anonymous volumes are created when an image has a VOLUME instruction. They will initialize by copying any of the existing content at the mount point (unlike a bind mount volume which typically replaces content at the mount point):
- With
docker run --rm ..., each container instance started will create a new anonymous volume. Without the--rm, these will accumulate pointlessly while the user may not be aware of this implicit waste on their system. - Docker Compose behaves differently, with additional logic to preserve the same anonymous volume across instances of the container for a given compose project.
The VOLUME instruction provides no value to an image. It only causes problems.
For detailed justification, please see below context for my previous write-up on this subject:
- fix:
Dockerfile-VOLUMEdirective is an anti-pattern kanidm/kanidm#2948 Dockerfile: RemoveVOLUMEinstruction ory/hydra#3683- Remove
VOLUMEinstructions caddyserver/caddy-docker#118 (comment) - Example of implicit 2GB disk usage per container instance (not applicable to images with empty
VOLUMEpublished, but clearly documents aVOLUMEconcern)
For reference, this image previously has already previously removed another VOLUME instruction (but it lacks any context as to why)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels