简体   繁体   English

docker - 装载的文件在容器中为空

[英]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
  • The container starts容器启动
  • the file exists文件存在
  • but the file is empty但是文件是空的

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.

相关问题 Docker 容器挂载文件共享路径未更新 - Docker container mounted file share path not updating 由docker容器写入已装入卷的文件的所有权 - ownership of files that are written by the docker container to mounted volume Docker容器未显示已装载的卷-访问问题 - Docker container not showing volume mounted - Access issue 在主机上更改已装入卷中的文件时,未在docker容器中触发文件系统事件 - File system events not triggered in docker container when files in mounted volume are changed on the host 写入已安装目录中的文件时,docker容器会不断增加内存使用量 - docker container keep increasing memory usage when writing into a file in a mounted directory spring 引导应用程序 docker 容器中的日志文件为空 - Logs file is empty in spring boot application docker container 在 Docker 中作为目录安装的单个文件卷 - Single file volume mounted as directory in Docker Docker 节点在挂载的卷上找不到文件 - Docker node cannot find file on mounted volume 安装到linux docker容器卷的Windows文件夹不显示所有文件夹 - Windows folder mounted to linux docker container volume not displaying all folders 为什么我安装的docker卷文件会变成容器内的文件夹? - Why are my mounted docker volume files turning into folders inside the container?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM