'docker run' using mount volume option '-v' with single directory as parameter (no source and destination split with colon mark (“:”))

可紊 提交于 2021-01-29 07:17:57

问题


On this page https://mherman.org/blog/dockerizing-an-angular-app/ ,

At some point in this tutorial there is this command to launch the container: $ docker run -v ${PWD}:/app -v /app/node_modules -p 4201:4200 --rm example:dev.

I don't understand the -v /app/node_modules part. What is the purpose of -v when there are no source and destination split by a colon mark?

I've been reading official documentation:

  • https://docs.docker.com/engine/reference/commandline/run/#mount-volume--v---read-only ;
  • https://docs.docker.com/storage/bind-mounts/ ;
  • and https://docs.docker.com/storage/volumes/ .

I don't see an example and explanation about docker run -v [some absolute path directory by itself] [container image name].

I understand the behaviour of:

  • docker run -v [the source, an absolute path on the host to map to a destination within the container]:[the destination, an absolute path in the container] [container image name] ;
  • and docker run -v [the source, a docker volume name to map to a destination within the container]:[the destination, an absolute path in the container] [container image name] .

But I don't get what is the expected behaviour of that: docker run -v [some absolute path directory by itself] [container image name].

What is -v [some absolute path directory by itself], like -v /app/node_modules; how does it articulate between the host and the container?


回答1:


the docker run command supports most of Dockerfile commands, among which the VOLUME

The VOLUME instruction creates a mount point with the specified name and marks it as holding externally mounted volumes from native host or other containers.

The docker run command initializes the newly created volume with any data that exists at the specified location within the base image.

usually, this is called anonymous volume

Anonymous volumes have no specific source so when the container is deleted, instruct the Docker Engine daemon to remove them.

when --volume is given a single argument, the behavior creates an empty directory within the container

When the host directory of a bind-mounted volume doesn’t exist, Docker will automatically create this directory on the host for you.



来源:https://stackoverflow.com/questions/64076355/docker-run-using-mount-volume-option-v-with-single-directory-as-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!