[英]Docker Volumes mounting issue
I am trying to dynamically mount a volume from the container to the host and it works but there is a hitch. 我正在尝试从容器到主机动态挂载卷,并且它可以正常工作,但是有麻烦。 I am using the following command:
我正在使用以下命令:
docker run -it --name Test1 -v $HOME/.myapp_configs/specificConfig.txt:/bin/specificConfig.txt:rw docker-image /bin/bash
The issue lies in that if the mount point on the host does not exist the docker command creates it but assigns it root:root
rather than $USER:$USER
like I would expect. 问题在于,如果主机上的挂载点不存在,则docker命令会创建它,但将其分配为
root:root
而不是像我期望的那样分配给$USER:$USER
。 I gather that this is more than likely a direct result of the namespace mapping issue that has been identified with Docker. 我认为这很可能是Docker已经发现的名称空间映射问题的直接结果。
Does anyone have any thoughts on how I can force the host mount point to be created with the appropriate permissions? 是否有人对如何强制使用适当的权限创建主机挂载点有任何想法? ie
即
drwxr-xr-x. 3 $USER $USER 31 Aug 21 15:02 ~/.myapp_configs/specificConfig.txt
instead of... 代替...
drwxr-xr-x. 3 root root 31 Aug 21 15:02 ~/.myapp_configs/specificConfig.txt
Thanks, 谢谢,
Bruce 布鲁斯
What about making sure the file exists before running the container? 在运行容器之前确保文件存在该怎么办?
the command could look like: 该命令可能类似于:
test -f $HOME/.myapp_configs/specificConfig.txt || touch $HOME/.myapp_configs/specificConfig.txt
docker run -it --name Test1 -v $HOME/.myapp_configs/specificConfig.txt:/bin/specificConfig.txt:rw docker-image /bin/bash
explanation: 说明:
test -f <some file>
will have exit status 0
if the file exists test -f <some file>
退出状态为0
||
will execute the following command only if the previous command exit status is different than 0
0
才执行以下命令 touch <some file>
modify an existing file modification time, or (and this is our case) create an empty file touch <some file>
修改现有文件的修改时间,或(这是我们的情况)创建一个空文件 Of course, if inside your container lies some code that acts differently whether the file exists or not, then you would have to adapt that code to check if the file is empty instead. 当然,如果您的容器中包含一些代码,无论文件是否存在 ,它们的行为都不同,那么您将不得不修改该代码以检查文件是否为空 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.