我正在尝试使用docker安装sontype nexus,并希望与主机(linux ubuntu 14.04)/opt/nexus
共享docker /opt/sonatype-work
nexus repo。
我的档案:
FROM centos:6
MAINTAINER Marcel Birkner <marcel.birkner@codecentric.de>
USER root
# Update the system
RUN yum -y update;
yum clean all
##########################################################
# Install Java JDK, SSH and other useful cmdline utilities
##########################################################
RUN yum -y install java-1.7.0-openjdk-devel
which
telnet
unzip
openssh-server
sudo
openssh-clients
iputils
iproute
httpd-tools
wget
tar;
yum clean all
ENV JAVA_HOME /usr/lib/jvm/jre
##########################################################
# Install Nexus
##########################################################
RUN mkdir -p /opt/sonatype-nexus /opt/sonatype-work
RUN wget -O /tmp/nexus-latest-bundle.tar.gz http://www.sonatype.org/downloads/nexus-latest-bundle.tar.gz
RUN tar xzvf /tmp/nexus-latest-bundle.tar.gz -C /opt/sonatype-nexus --strip-components=1
RUN useradd --user-group --system --home-dir /opt/sonatype-nexus nexus
ADD nexus.xml /opt/sonatype-work/nexus/conf/nexus.xml
RUN chown -R nexus:nexus /opt/sonatype-work /opt/sonatype-nexus
ENV NEXUS_WEBAPP_CONTEXT_PATH /nexus
RUN echo "#!/bin/bash" > /opt/start-nexus.sh
RUN echo "su -c "/opt/sonatype-nexus/bin/nexus console" - nexus" >> /opt/start-nexus.sh
RUN chmod +x /opt/start-nexus.sh
VOLUME /opt/sonatype-work
CMD ["/opt/start-nexus.sh"]
EXPOSE 8081
当我构建此映像时(构建成功):
docker build -t sonatype/nexus .
然后我用这个命令运行它:
docker run -d -p 8081:8081 --name nexus -v /opt/nexus:/opt/sonatype-work sonatype/nexus
它立即启动并停止显示错误(docker logs nexus
):
nexus_1 | jvm 1 | Caused by: java.nio.file.AccessDeniedException: /opt/sonatype-work/nexus
nexus_1 | jvm 1 | at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84) ~[na:1.7.0_99]
nexus_1 | jvm 1 | at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102) ~[na:1.7.0_99]
nexus_1 | jvm 1 | at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107) ~[na:1.7.0_99]
nexus_1 | jvm 1 | at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:383) ~[na:1.7.0_99]
nexus_1 | jvm 1 | at java.nio.file.Files.createDirectory(Files.java:630) ~[na:1.7.0_99]
nexus_1 | jvm 1 | at java.nio.file.Files.createAndCheckIsDirectory(Files.java:734) ~[na:1.7.0_99]
nexus_1 | jvm 1 | at java.nio.file.Files.createDirectories(Files.java:720) ~[na:1.7.0_99]
nexus_1 | jvm 1 | at org.sonatype.nexus.util.file.DirSupport.mkdir(DirSupport.java:146) ~[na:na]
nexus_1 | jvm 1 | at org.sonatype.nexus.util.file.DirSupport.mkdir(DirSupport.java:162) ~[na:na]
nexus_1 | jvm 1 | at org.sonatype.nexus.webapp.WebappBootstrap.contextInitialized(WebappBootstrap.java:115) ~[na:na]
nexus_1 | jvm 1 | ... 16 common frames omitted
nexus_1 | wrapper | <-- Wrapper Stopped
如果我从dockerfile中删除了CCD_ 4,它就可以正常工作。
你知道是什么导致了这个问题吗?以及如何修复?
如果绑定装载容器中的主机目录,主机目录中的文件和目录将优先于容器映像中已经存在的文件。换句话说,它们"掩盖"了容器下面的东西。
绑定装载保留其对主机上存在的目录的权限,如果主机上不存在目录,Docker将使用root:root
作为所有者创建该目录。
查看Dockerfile中的useradd nexus
,我怀疑start-nexus.sh
与该用户一起运行nexus,因此它可能没有绑定安装目录(由root拥有)的权限。您可以通过将目录chowning
更改为容器内nexus
的数字uid/gid来修复此问题。
要获取该用户的uid
/gid
,请交互启动容器;
docker run -it --rm sonatype/nexus bash
在这个shell中请求uid/gid:
id nexus
这给了你类似的东西:
uid=123(nexus) gid=456(nexus) groups=456(nexus)
现在退出容器(exit
),并使用uid/gid chown主机上的目录;
sudo chown -R 123:456 /opt/nexus
我注意到的一些事情
看起来您正在构建自己的自定义版本的奏鸣型nexus图像,但使用与官方图像相同的名称(sonatype/nexus
)。我建议不要这样做,并给它起自己的名字(例如mycompany/nexus
);这可以防止混乱,也可以防止你自己如果有人运行docker pull sonatype/nexus
,则要用官方图像覆盖的图像。
有什么理由不使用官方图片吗?一般来说,建议使用官方图像,因为它们由软件的维护者维护(在这种情况下是sonateype),因此应该为您提供软件的最新(和维护的)版本;https://hub.docker.com/r/sonatype/nexus/
小心selinux
运行setenforce 0
,如果有帮助,请考虑通过设置永久禁用它SELINUX=disabled
在里面/etc/sysconfig/selinux
配置文件。