what does VOLUME command do in Dockerfile?

前端 未结 3 1934
鱼传尺愫
鱼传尺愫 2021-02-13 01:33

I am having it difficulty in understanding added advantage of VOLUME(https://docs.docker.com/engine/reference/builder/#volume) .

In Dockerfile one can have mkdir to cre

相关标签:
3条回答
  • 2021-02-13 02:00

    The VOLUME command will specify a mount point in the container. This mount point will be mapped to a location on the host that is either specified when the container is created or if not specified chosen automatically from a directory created in /var/lib/docker/volumes.

    If the directory chosen as the mount point contains any files then these files will be copied into this volume. The advantage over mkdir is that it will persist the files to a location on the host machine after the container is terminated.

    It appears some people have questioned why you would use the VOLUME command since it creates an anonymous volume. Anonymous volumes don't have much use any more and are basically an artifact of the early days of Docker before volumes could be named. You would normally specify the volume name when creating the container:

    docker container run -v my-volume:/data image_tag

    In this example, /data is the mount point in the container and my-volume is the volume on the local host. If my volume does not exist when this command is run then it is created on the local host.

    0 讨论(0)
  • 2021-02-13 02:13

    The mkdir in the Dockerfile will make a directory within that container only. A volume can be on the host machine or a different container, and so remains in existence when the container is killed.

    0 讨论(0)
  • 2021-02-13 02:15

    A volume is very helpful when we don't want to lose data once the container is deleted. A configuration file, a database data, etc. Hence, you are able to use the same volume with a complete new docker container. If you only create a directory within the Dockefile, the data inside the folder will be deleted toghether with the container.

    0 讨论(0)
提交回复
热议问题