我正在尝试使用Docker安装Sonatype Nexus,并希望与主机(Linux Ubuntu 14.04)共享Docker /opt/sonatype-work
Nexus仓库中的内容到主机的/opt/nexus
目录。
我的Dockerfile:
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中删除VOLUME /opt/sonatype-nexus
,它就可以正常工作。
您有任何想法是什么原因导致了这个问题?如何解决?
/opt/nexus
的所有者更改为docker用户的问题,感谢@thaJeztah。最终我切换到官方镜像sonatype/nexus
,nexus uid在dockerfile中被指定为200,所以我只需要更改我的目录所有者即可,现在一切都正常工作了。 - Gimbo