问题描述
在此页面https://mherman.org/blog/dockerizing-an-angular-app/上,
在本教程的某个时候,有以下命令来启动容器:
$ docker run -v ${PWD}:/app -v /app/node_modules -p 4201:4200 --rm example:dev
。
我不了解-v /app/node_modules
部分。如果-v
没有用冒号分隔的源地址和目标地址,那么有什么用途?
我一直在阅读官方文档:
- https://docs.docker.com/engine/reference/commandline/run/#mount-volume--v---read-only;
- https://docs.docker.com/storage/bind-mounts/;
- 和https://docs.docker.com/storage/volumes/。
我没有看到有关docker run -v [some absolute path directory by itself] [container image name]
的示例和说明。
我了解以下行为:
-
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]
; - 和
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]
。
但是我不知道该怎么做:docker run -v [some absolute path directory by itself] [container image name]
。
什么是-v [some absolute path directory by itself]
,例如-v /app/node_modules
;主机和容器之间如何衔接?
解决方法
docker run
命令支持大多数Dockerfile
命令,其中VOLUME
VOLUME
指令创建具有指定名称的安装点,并将其标记为保存来自本机主机或其他容器的外部安装的卷。
docker run
命令使用基础映像内指定位置上存在的任何数据初始化新创建的卷。
通常称为anonymous volume
匿名卷没有特定来源,因此当删除容器时,请指示Docker Engine守护程序将其删除。
--volume
is given a single argument时,该行为会在容器内创建一个空目录
当绑定安装的卷的主机目录不存在时,Docker会自动在主机上为您创建此目录。