简体   繁体   English

共享主机驱动器安装到两个Docker容器的权限问题

[英]Permissions issue with shared host drive mounted to two docker containers

Given I have 2 containers, Weblogic and Tomcat. 鉴于我有2个容器,Weblogic和Tomcat。

Weblogic runs under oracle user, Tomcat runs under root user. Weblogic在oracle用户下运行,Tomcat在root用户下运行。

I use the same volume mapping for both services, so that application deployed in Tomcat orchestrates business process in which application deployed in Weblogic saves files to that shared folder. 我为这两种服务使用相同的卷映射,以便部署在Tomcat中的应用程序协调业务流程,其中部署在Weblogic中的应用程序将文件保存到该共享文件夹中。

I came across the issue with permissions because Tomcat runs under root (creates directory structure with root owner and group) and Weblogic running under oracle can't save files. 我遇到了具有权限的问题,因为Tomcat在root下运行(使用root所有者和组创建目录结构),而在oracle下运行的Weblogic无法保存文件。

What is the best way to handle shared host data folder between two containers and avoid problems with permissions? 处理两个容器之间的共享主机数据文件夹并避免权限问题的最佳方法是什么?

The unix/linux solutions to this are to use either: 对此的unix / linux解决方案使用以下任一方法:

  1. The same UID and open permissions on the user 用户的相同UID和打开权限
  2. The same GID and open permissions on the group 该组具有相同的GID和打开权限
  3. None of the above and open permissions for everyone 以上都不是,所有人都可以使用的开放权限

These options all apply identically for apps running inside of containers. 这些选项都同样适用于在容器内部运行的应用程序。

The third option is least ideal since it allows anyone on the host to modify these files. 第三个选项是最不理想的,因为它允许主机上的任何人修改这些文件。 However, implementing it is a quick chmod -R 777 dir and updating the umask to be 000 for any apps that create files in that directory. 但是,实现它是一个快速的chmod -R 777 dir ,对于在该目录中创建文件的所有应用程序,将umask更新为000。

That leaves option 1 or 2. Option 1 means either dropping root for Tomcat, or running Weblogic as root, the former being preferred but may not be possible depending on the app. 这留下了选项1或2。选项1意味着要么为Tomcat删除root,要么以root身份运行Weblogic,前者是首选,但根据应用程序的不同,可能无法实现。

If option 1 isn't possible, try using a common group between the two apps. 如果无法使用选项1,请尝试在两个应用程序之间使用一个公共组。 Add the users to the same GID in both images, and in your directory, change the group to that common GID and set the group sticky bit in your permissions to ensure every file in that directory are also created as that group. 将用户添加到两个映像中的相同GID中,然后在您的目录中,将该组更改为该通用GID,并在您的权限中设置组粘性位,以确保该目录中的每个文件也都作为该组创建。

chgrp $gid dir
chmod g+s dir

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

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