Best practice - Anonymous volume vs bind mount

前端 未结 2 437
别跟我提以往
别跟我提以往 2021-01-19 05:36

In a container,

anonymous volume can be created

with syntax(VOLUME /build) in Dockerfile

or

below syntax with

2条回答
  •  一整个雨季
    2021-01-19 06:25

    Actually, anonymous volumes (/build) usage is encouraged over the use of bind mounts (/tmp/cache:/cache):

    Volumes have several advantages over bind mounts:

    • Volumes are easier to back up or migrate than bind mounts.
    • You can manage volumes using Docker CLI commands or the Docker API.
    • Volumes work on both Linux and Windows containers.
    • Volumes can be more safely shared among multiple containers.
    • Volume drivers let you store volumes on remote hosts or cloud providers, to encrypt the contents of volumes, or to add other functionality.
    • New volumes can have their content pre-populated by a container.

    Regarding your second question, yes. You can create anonymous volumes in docker-compose file or in the Dockerfile. No need to specify in both places.

提交回复
热议问题