nexus3 docker 容器中的权限问题

Dan*_*ski 5 docker nexus3

当我在 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
Run Code Online (Sandbox Code Playgroud)

它表明存在文件权限问题。我使用 Red Hat Enterprise Linux 7.5 作为主机和最新的 docker 版本。

在另一台机器(ubuntu)上它工作正常。

该问题发生在持久卷 (/nexus-data) 中。但是,我没有挂载特定的卷,而是让 docker 使用匿名卷。

如果我比较两台机器上的卷,我可以看到以下权限:

对于 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
Run Code Online (Sandbox Code Playgroud)

在 ubuntu 上,它工作的地方属于 nexus。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
Run Code Online (Sandbox Code Playgroud)

使用选项 -u 更改用户不是一个选项。

Dan*_*ski 2

我可以通过删除所有本地 docker 镜像来解决这个问题:docker image prune -a

之后它再次下载图像并且成功了。这很奇怪,因为我还比较了图像的指纹,它们是相同的。