简体   繁体   English

docker挂载主机目录文件权限

[英]docker mounted host directory file permissions

I am running the mqtt broker Mosqitto in a docker image. 我正在docker映像中运行mqtt经纪人Mosqitto。 I am using the following arguments 我正在使用以下参数

sudo docker run -d -p 1883:1883 -p 1884:1884 -v /home/mosquitto/apps/dev/mosquitto:/mosquitto --restart always -u mosquitto eclipse-mosquitto:1.4.

This should mount the host folder /home/mosquitto/apps/dev/mosquitto to the image folder /mosquitto The problem is that the host user IDs (1001) and the docker user IDs (100) do not match. 这会将主机文件夹/ home / mosquitto / apps / dev / mosquitto安装到映像文件夹/ mosquitto。问题是主机用户ID(1001)和Docker用户ID(100)不匹配。

If I do not specify -u mosquitto, the application complains about not being able to write to /mosquitto/logs/mosquitto.log 如果我未指定-u mosquitto,则应用程序会抱怨无法写入/mosquitto/logs/mosquitto.log

So I thought I'd specify -u mosquitto, to make the application inside the image run as user 1001, and therefore have write access to the mounted files. 因此,我想我要指定-u mosquitto,以使映像中的应用程序以用户1001的身份运行,因此具有对已装入文件的写访问权。 Which worked. 哪个有效。 But then, the Mosquitto application made a new database file on exit. 但是,Mosquitto应用程序在退出时创建了一个新的数据库文件。 That file was made with the 101 user as owner.. 该文件是由101用户作为所有者创建的。

What exactly happens when I specify -U to docker. 当我为docker指定-U时会发生什么。 How come it kind of did what I was expecting (allowed writing to host files) and kind of didn't do what I was expecting(still made files with the original image user id) 怎么达到我的期望(允许写入主机文件)而没有达到我的期望(仍然使用原始图像用户ID制作文件)

Maybe this is something to do with this specific docker image .. it runs some script internally that switches user? 也许这与特定的docker映像有关..它在内部运行了一些切换用户的脚本?

How about making write access to log path for any user? 如何对任何用户进行日志路径的写访问? It may be less secure. 它可能不太安全。 But if it is just logs, lets see application inside docker can write to it. 但是,如果只是日志,让我们看看docker内部的应用程序可以对其进行写入。

Or think about bootstrap some commands to the container to make permission changes inside. 或者考虑将一些命令引导至容器以在内部进行权限更改。

If you are using Linux or OSX for your Docker location, most likely it is a security or file permissions issue. 如果您在Docker位置使用Linux或OSX,则很可能是安全性或文件权限问题。 Go to this bug report Permission denied for directories created automatically by Dockerfile ADD command #1295 and jump to the end...there are several links to sub-bug reports where you can most likely find your solution. 转到此错误报告Dockerfile ADD命令#1295自动创建的目录的权限被拒绝,并跳到最后...有几个子错误报告的链接,您很可能在其中找到解决方案。 I had a very similar issue, and it turned out to be a selinux misconfiguration. 我有一个非常类似的问题,事实证明这是selinux配置错误。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM