我有一个带有以下mkdir命令的docker文件。
RUN mkdir /home/jenkins/.m2
在构建docker映像时,出现以下错误。
mkdir: cannot create directory '/home/jenkins/.m2': Permission denied
下面是我的dockerfile:
FROM ubuntu:18.04
ENV REPOSITORY_PATH /home/jenkins/test
ENV JBOSS_HOME /home/jenkins
ENV SEDI_TOOLS_HOME /home/jenkins/install/tools
RUN mkdir /home/jenkins/Application
COPY --chown=jenkins:jenkins . /home/jenkins/Application/
RUN chmod ugo+x /home/jenkins/Application/ApplicationParent/build_Application/wildfly.sh
WORKDIR /home/jenkins/Application/ApplicationParent/build_Application
COPY --chown=jenkins:jenkins ./ApplicationParent/build_Application/.jboss-cli.truststore /home/jenkins/
WORKDIR /home/jenkins/Application/ApplicationParent/build_Application
USER jenkins
RUN mkdir /home/jenkins/.m2
CMD ["/home/jenkins/maven/apache-maven-3.3.9/bin/mvn","package","-DskipTests"]
有人可以帮我吗?
谢谢。
答案 0 :(得分:1)
您不是要在Dockerfile中创建jenkins
用户吗?并且/home/jenkins/
由root
用户创建,因此,Jenkins用户将获得拒绝权限。
另外,Will建议使用正式的Jenkins图像,而不要与基于alpine的轻量级Ubuntu混为一谈。
因此,最好根据官方图像进行创建并根据需要扩展图像。
FROM jenkins/jenkins:alpine
.
.
.
高山的基础图像只有 160MB ,那么您需要使用如此沉重的图像,而主要的东西就在您身边吗?
如果您想获得较重的图像,请尝试以下操作。
RUN adduser --disabled-password --gecos '' jenkins
USER jenkins
RUN mkdir /home/jenkins/Application
COPY . /home/jenkins/Application/
RUN chmod ugo+x /home/jenkins/Application/ApplicationParent/build_Application/wildfly.sh
WORKDIR /home/jenkins/Application/ApplicationParent/build_Application
COPY ApplicationParent/build_Application/.jboss-cli.truststore /home/jenkins/
WORKDIR /home/jenkins/Application/ApplicationParent/build_Application
RUN mkdir /home/jenkins/.m2
答案 1 :(得分:1)
在dockerfile中创建一个新的use jenkins来解决此权限问题,如下所示:
# Create new jenkins user
RUN adduser --gecos "" --disabled-password --quiet jenkins
RUN echo "jenkins:jenkins" | chpasswd
并将目录/ home / jenkins的权限更改为用户jenkins,如下所示:
RUN chown jenkins:jenkins /home/jenkins