我想在Docker上使用Jenkins设置CI / CD平台,我有一个Dockerfile,该文件通过插件,作业,管道,用户等来设置Jenkins。 但是,在启动Jenkins时,我进行了全新安装,并且所有设置都被覆盖。我想念某个地方的标志吗?
答案 0 :(得分:0)
FROM jenkins/jenkins:lts
USER root
# force Jenkins to be a sudoer
RUN apt-get update \
&& apt-get install -y vim sudo curl\
&& rm -rf /var/lib/apt/lists/*
RUN echo "jenkins ALL=NOPASSWD: ALL" >> /etc/sudoers
# install docker-ce
RUN apt -y update && \
apt -y upgrade && \
apt -y install sudo apt-transport-https ca-certificates curl software-properties-common gnupg2 && \
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add - && \
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" && \
apt -y update && \
apt -y install docker-ce
# install Maven
RUN cd /usr/local && \
wget https://www-us.apache.org/dist/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz && \
tar -zxvf apache-maven-3.6.0-bin.tar.gz && \
mv apache-maven-3.6.0 apache-maven && \
rm apache-maven-3.6.0-bin.tar.gz
COPY maven.sh /etc/profile.d
RUN chmod +x /etc/profile.d/maven.sh
# install Oracle Java 11
WORKDIR /usr/local
RUN wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; \
oraclelicense=accept-securebackup-cookie" \
https://download.oracle.com/otn-pub/java/jdk/11.0.1+13/90cf5d8f270a4347a95050320eef3fb7/jdk-11.0.1_linux-x64_bin.tar.gz && \
tar -zxvf jdk-11.0.1_linux-x64_bin.tar.gz && \
rm jdk-11.0.1_linux-x64_bin.tar.gz
COPY install-plugins.sh /usr/local/bin/install-plugins.sh
COPY jenkins-support /usr/local/bin/jenkins-support
# install all plugins
COPY plugins.txt /var/jenkins_home/plugins.txt
RUN chmod +x /usr/local/bin/install-plugins.sh
RUN xargs /usr/local/bin/install-plugins.sh < /var/jenkins_home/plugins.txt
# Install all jobs, pipelines, users and environment
ADD jenkins.tar.gz $JENKINS_HOME
# copy script-security disable
COPY groovy/disable-script-security.groovy /var/jenkins_home/init.groovy.d
RUN echo 2.0 > /usr/share/jenkins/ref/jenkins.install.UpgradeWizard.state
答案 1 :(得分:0)
您只需要在运行容器时使用卷:
例如,下面的示例实例化一个名为 jenkins 的容器,并使用 / var / jenkins_home 在主机中安装路径 / my_server / jenkins_home strong>容器内:
docker run -t --name jenkins -p 8080:8080 -v /my_server/jenkins_home:/var/jenkins_home jenkins
因此,当您启动或停止容器时,主机服务器中的该文件夹将完整保留 / my_server / jenkins_home 并将用于您的容器。 Jenkins中的所有配置都可以使用。
https://docs.docker.com/storage/volumes/#choose-the--v-or---mount-flag
答案 2 :(得分:0)
这是我的解决方案:
FROM jenkins/jenkins:lts
USER root
# force Jenkins to be a sudoer
RUN apt-get update \
&& apt-get install -y vim sudo curl\
&& rm -rf /var/lib/apt/lists/*
RUN echo "jenkins ALL=NOPASSWD: ALL" >> /etc/sudoers
ARG JENKINS_HOME=/var/jenkins_home
ENV JENKINS_HOME $JENKINS_HOME
ENV JAVA_OPTS -Djenkins.install.runSetupWizard=false
# install docker-ce
RUN apt -y update && \
apt -y upgrade && \
apt -y install sudo apt-transport-https ca-certificates curl software-properties-common gnupg2 && \
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add - && \
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" && \
apt -y update && \
apt -y install docker-ce
# install Maven
RUN cd /usr/local && \
wget https://www-us.apache.org/dist/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz && \
tar -zxvf apache-maven-3.6.0-bin.tar.gz && \
mv apache-maven-3.6.0 apache-maven && \
rm apache-maven-3.6.0-bin.tar.gz
COPY maven.sh /etc/profile.d
RUN chmod +x /etc/profile.d/maven.sh
# install Oracle Java 11
WORKDIR /usr/local
RUN wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; \
oraclelicense=accept-securebackup-cookie" \
https://download.oracle.com/otn-pub/java/jdk/11.0.1+13/90cf5d8f270a4347a95050320eef3fb7/jdk-11.0.1_linux-x64_bin.tar.gz && \
tar -zxvf jdk-11.0.1_linux-x64_bin.tar.gz && \
rm jdk-11.0.1_linux-x64_bin.tar.gz
COPY install-plugins.sh /usr/local/bin/install-plugins.sh
COPY jenkins-support /usr/local/bin/jenkins-support
# install all plugins
COPY plugins.txt /var/jenkins_home/plugins.txt
RUN chmod +x /usr/local/bin/install-plugins.sh
RUN xargs /usr/local/bin/install-plugins.sh < /var/jenkins_home/plugins.txt
# Install all jobs, pipelines, users and environment
ADD jenkins.tar.gz /usr/share/jenkins/ref/
# copy script-security disable
COPY groovy/disable-script-security.groovy /var/jenkins_home/init.groovy.d
答案 3 :(得分:0)
对我有用的解决方法是将-Djenkins.install.runSetupWizard附加到jenkins选项。请参阅下面的我的dockerfile:
initialState