简体   繁体   English

由docker容器写入已装入卷的文件的所有权

[英]ownership of files that are written by the docker container to mounted volume

I'm using non-root user on a secured env to run stock DB docker container (elasticsearch). 我在安全的env上使用非root用户来运行stock DB docker container(elasticsearch)。 Of course - I want the data to be mounted so I won't lose it when the container is destroyed. 当然 - 我希望安装数据,这样当容器被销毁时我不会丢失它。

The problem is that this container writes to that volume with root ownership, and then the host doesn't have permissions to move/rm them. 问题是此容器使用root所有权写入该卷,然后主机无权移动它们。

I know that most docker images use root user from inside, but how can I control the file ownership of the hosting machine? 我知道大多数docker镜像从内部使用root用户,但是如何控制托管机器的文件所有权?

You can create a data container docker create -v /usr/share/elasticsearch/data --name esdata elasticsearch /bin/true , then use it in your container docker run -d --volumes-from esdata --name some-elasticsearch elasticsearch . 你可以创建一个数据容器docker create -v /usr/share/elasticsearch/data --name esdata elasticsearch /bin/true ,然后在你的容器docker run -d --volumes-from esdata --name some-elasticsearch elasticsearch

This is a prefer data pattern for docker, you can find out more in this docker page. 这是docker的首选数据模式,您可以在 docker页面中找到更多信息。

To answer you question use "docker run --user '$(id -u)' ..." it will run program within container with current user id, then you might have the same question as I did. 要回答你的问题,请使用“docker run --user'$(id -u)'...”它将使用当前用户ID在容器中运行程序,然后你可能会遇到与我相同的问题。

I answered it in some way I hope it might be useful. 我以某种方式回答它,希望它可能有用。 Docker with '--user' can not write to volume with different ownership 具有“--user”的Docker无法写入具有不同所有权的卷

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我安装的docker卷文件会变成容器内的文件夹? - Why are my mounted docker volume files turning into folders inside the container? Docker容器未显示已装载的卷-访问问题 - Docker container not showing volume mounted - Access issue Docker挂载卷不跟踪Nginx日志文件 - Docker mounted volume not tracking nginx log files 在主机上更改已装入卷中的文件时,未在docker容器中触发文件系统事件 - File system events not triggered in docker container when files in mounted volume are changed on the host 在 Ubuntu 上运行 docker:安装的主机卷不可从容器写入 - Running docker on Ubuntu: mounted host volume is not writable from container 安装到linux docker容器卷的Windows文件夹不显示所有文件夹 - Windows folder mounted to linux docker container volume not displaying all folders Docker:已安装卷的权限 - Docker: Permissions for a mounted volume Docker-卷未在容器中挂载最新文件 - Docker - Volume not mounting latest files in container docker 容器的用户权限是否会影响主机对 docker-compose.yml 中挂载卷的权限? - Can user privilege of docker container impact permission of host machine on mounted volume in docker-compose.yml? 如果主机文件夹被删除,为什么 docker 容器仍然可以写入已安装的卷? - Why can a docker container still write to a mounted volume if the host folder is deleted?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM