[英]docker - mounted file is empty in container
I have the following docker run
command that I send via ssh from my CI (as the problem also happens when I try it on the server directly I skip all ssh related stuff here).我有以下
docker run
命令,我通过 ssh 从我的 CI 发送(因为当我直接在服务器上尝试它时也会发生问题,我在这里跳过所有 ssh 相关的东西)。
docker run --name amc-node-be -d -p 10.0.0.3:3000:3000 --mount type=bind,source=/etc/amc-node-be/.env,target=/app/dist/amc-node-be/.env,readonly --restart unless-stopped .../amc-node-be:latest
I guess it has something to do with file permissions but I don't understand enough how the permissions of the host leak through to the container using a bind mount or maybe I don't understand linux file permissions enough.我想这与文件权限有关,但我不太了解主机的权限如何使用绑定安装泄漏到容器,或者我可能不太了解 linux 文件权限。 On the host I gave read permissions to the docker group on the.env file.
在主机上,我授予 docker 组对 .env 文件的读取权限。
/etc/amc-node-be$ ls -la
total 12
drwxr-x---+ 2 andymatic docker 4096 Oct 2 10:20 .
drwxr-xr-x 85 root root 4096 Oct 2 12:13 ..
-rwxr-----+ 1 andymatic docker 912 Oct 2 09:40 .env
The deploy user is in the docker group deploy用户在docker组
$ sudo -u deploy groups
docker
With sudo -u deploy cat /etc/amc-node-be/.env
on the host I get the content of the file在主机上使用
sudo -u deploy cat /etc/amc-node-be/.env
我得到了文件的内容
docker inspect amc-node-be
returns docker inspect amc-node-be
返回
"Mounts": [
{
"Type": "bind",
"Source": "/etc/amc-node-be/.env",
"Destination": "/app/dist/amc-node-be/.env",
"Mode": "",
"RW": false,
"Propagation": "rprivate"
}
]
Any other idea what I do wrong?任何其他想法我做错了什么?
I think you should use the --env-file option:我认为你应该使用 --env-file 选项:
docker run --env-file=.env --name amc-node-be -d -p 10.0.0.3:3000:3000 --restart unless-stopped .../amc-node-be:latest
With env-file you can reference the filename, which is parsed to extract the environment variables to set.使用 env-file 您可以引用文件名,该文件名被解析以提取要设置的环境变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.