简体   繁体   English

nexus3 docker 容器中的权限问题

[英]Permission issues in nexus3 docker container

When I start nexus3 in a docker container I get the following error messages.当我在 docker 容器中启动 nexus3 时,我收到以下错误消息。

$ docker run --rm sonatype/nexus3:3.8.0
Warning:  Cannot open log file: ../sonatype-work/nexus3/log/jvm.log
Warning:  Forcing option -XX:LogFile=/tmp/jvm.log
Java HotSpot(TM) 64-Bit Server VM warning: Cannot open file ../sonatype-work/nexus3/log/jvm.log due to Permission denied

Unable to update instance pid: Unable to create directory /nexus-data/instances
/nexus-data/log/karaf.log (Permission denied)
Unable to update instance pid: Unable to create directory /nexus-data/instances

It indicates that there is a file permission issue.这表明存在文件权限问题。 I am using Red Hat Enterprise Linux 7.5 as host machine and the most recent docker version.我使用 Red Hat Enterprise Linux 7.5 作为主机和最新的 docker 版本。

On another machine (ubuntu) it works fine.在另一台机器(ubuntu)上它工作正常。

The issue occurs in the persistent volume (/nexus-data).该问题出现在持久卷 (/nexus-data) 中。 However, I do not mount a specific volume and let docker use a anonymous one.但是,我没有挂载特定的卷,而是让 docker 使用匿名卷。

If I compare the volumes on both machines I can see the following permissions:如果我比较两台机器上的卷,我可以看到以下权限:

For Red Hat, where it is not working is belongs to root.对于 Red Hat,它不工作的地方属于 root。

$ docker run --rm sonatype/nexus3:3.8.0 ls -l /nexus-data              
total 0
drwxr-xr-x. 2 root root 6 Mar  1 00:07 etc
drwxr-xr-x. 2 root root 6 Mar  1 00:07 log
drwxr-xr-x. 2 root root 6 Mar  1 00:07 tmp

On ubuntu, where it is working it belongs to nexus.在 ubuntu 上,它在哪里工作,它属于 nexus。 Nexus is also the default user in the container. Nexus 也是容器中的默认用户。

$ docker run --rm sonatype/nexus3:3.8.0 ls -l /nexus-data
total 12
drwxr-xr-x 2 nexus nexus 4096 Mar  1 00:07 etc
drwxr-xr-x 2 nexus nexus 4096 Mar  1 00:07 log
drwxr-xr-x 2 nexus nexus 4096 Mar  1 00:07 tmp

Changing the user with the options -u is not an option.使用选项 -u 更改用户不是一个选项。

I could solve it by deleting all local docker images: docker image prune -a我可以通过删除所有本地 docker 图像来解决它: docker image prune -a

Afterwards it downloaded the image again and it worked.之后它再次下载了图像并且它工作了。 This is strange because I also compared the fingerprints of the images and they were identical.这很奇怪,因为我还比较了图像的指纹,它们是相同的。

You should attribute correct right to the folder where the persistent volume is located.您应该将正确的权限归于持久卷所在的文件夹。

chmod u+wxr -R <folder of /nexus-data volumes>

Be carefull, if you execute previous command, it would give write, read and execution right to all users.注意,如果你执行前面的命令,它会给所有用户写、读和执行的权利。 If you want to give more restricted right, you should modify the command.如果你想给予更多的限制权限,你应该修改命令。

An example of docker-compose for Nexus :用于 Nexus 的 docker-compose 示例:

version: "3"

services:

#Nexus
  nexus:
    image: sonatype/nexus3:3.39.0
    expose:
    - "8081"
    - "8082"
    - "8083"
    ports:
      # UI
      - "8081:8081"
      # repositories http
      - "8082:8082"
      - "8083:8083"
      # repositories https
      #- "8182:8182"
      #- "8183:8183"
    environment:
      - VIRTUAL_PORT=8081
    volumes:
      - "./nexus/data/nexus-data:/nexus-data"

Setup the volume :设置音量:

mkdir -p ./nexus/data/nexus-data
sudo chown -R 200 nexus/    # 200 because it's the UID of the nexus user inside the container

Start Nexus启动 Nexus

sudo docker-compose up -d

hf高频

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

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