Skip to content

Remove usage of the VOLUME instruction #639

@polarathene

Description

@polarathene

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.

VOLUME /var/lib/mysql

VOLUME /var/lib/mysql


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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions