从我的 Jenkins 容器 docker 安装中提取内容并传递到新容器
Extracting stuffs from my Jenkins container docker installation and passing to a new container
假设我有一个容器在工作!!
这是我的 Dockerfile...
FROM jenkinsci/blueocean
USER root
RUN apk update && apk add wget
RUN wget --no-verbose -O /tmp/apache-maven-3.6.3-bin.tar.gz https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
RUN tar xzf /tmp/apache-maven-3.6.3-bin.tar.gz -C /opt/
RUN ln -s /opt/apache-maven-3.6.3 /opt/maven
RUN ln -s /opt/maven/bin/mvn /usr/local/bin
RUN rm /tmp/apache-maven-3.6.3-bin.tar.gz
RUN chown jenkins:jenkins /opt/maven;
ENV MAVEN_HOME=/opt/mvn
现在我创建了图像...
docker build -t jenkins/blueocean_ci --no-cache .
现在我 运行 我的容器...
docker run -p 8080:8080 -p 50000:50000 --name jenkinsblue jenkins/blueocean_ci
我做了很多更改...插件安装和管道...
哦,我忘记了什么(不管做什么)
然后我把jenkins目录解压到d:\Documents\JenkinsBCK\
...
docker cp jenkinsblue:/var/jenkins_home d:\Documents\JenkinsBCK\
我想在 Windows d:\Documents\JenkinsBCK\
上保存对之前特定文件夹位置的更改,我会重复使用它。
现在,我使用像卷一样引用该目录创建了另一个容器,更改了端口...
docker run -v d:\Documents\JenkinsBCK:/var/jenkins_home -p 8081:8080 -p 50001:50000 --name jenkins_cnt jenkins/blueocean_ci
现在,我正在尝试用我的旧东西测试我的新容器...
http://localhost:8081/
您是否再次要求输入密码位于 /var/jenkins_home/secrets/initialAdminPassword
? hhmmm 没问题...
docker exec jenkins_cnt bash -c "cat /var/jenkins_home/secrets/initialAdminPassword"
我以前配置的插件和管道在哪里?
怎么了?
怎么做?
检查 $JENKINS_HOME
变量的值
docker exec JENKINS_CNT_SOURCE env
PATH=/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=b1f58b975483
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_ALL=en_US.UTF-8
JAVA_VERSION=jdk8u292-b10
JAVA_HOME=/opt/java/openjdk
JENKINS_HOME=/var/jenkins_home
JENKINS_SLAVE_AGENT_PORT=50000
REF=/usr/share/jenkins/ref
JENKINS_VERSION=2.277.4
JENKINS_UC=https://updates.jenkins.io
JENKINS_UC_EXPERIMENTAL=https://updates.jenkins.io/experimental
JENKINS_INCREMENTALS_REPO_MIRROR=https://repo.jenkins-ci.org/incrementals
COPY_REFERENCE_FILE_LOG=/var/jenkins_home/copy_reference_file.log
MAVEN_HOME=/opt/mvn
HOME=/var/jenkins_home
检查 xml 个文件
docker exec JENKINS_CNT_SOURCE bash -c "ls -al /var/jenkins_home/*.xml"
-rw-r--r-- 1 jenkins jenkins 1600 May 5 00:09 /var/jenkins_home/config.xml
-rw-r--r-- 1 jenkins jenkins 156 May 5 00:09 /var/jenkins_home/hudson.model.UpdateCenter.xml
-rw-r--r-- 1 jenkins jenkins 370 May 4 21:07 /var/jenkins_home/hudson.plugins.git.GitTool.xml
-rw-r--r-- 1 jenkins jenkins 179 May 4 21:18 /var/jenkins_home/jenkins.model.JenkinsLocationConfiguration.xml
-rw-r--r-- 1 jenkins jenkins 171 May 4 21:07 /var/jenkins_home/jenkins.telemetry.Correlator.xml
-rw-r--r-- 1 jenkins jenkins 907 May 5 00:09 /var/jenkins_home/nodeMonitors.xml
从源容器中提取文件
docker cp JENKINS_CNT_SOURCE:/var/jenkins_home/config.xml C:\BCKJenkins\
docker cp JENKINS_CNT_SOURCE:/var/jenkins_home/hudson.model.UpdateCenter.xml C:\BCKJenkins\
docker cp JENKINS_CNT_SOURCE:/var/jenkins_home/hudson.plugins.git.GitTool.xml C:\BCKJenkins\
docker cp JENKINS_CNT_SOURCE:/var/jenkins_home/jenkins.model.JenkinsLocationConfiguration.xml C:\BCKJenkins\
docker cp JENKINS_CNT_SOURCE:/var/jenkins_home/jenkins.telemetry.Correlator.xml C:\BCKJenkins\
docker cp JENKINS_CNT_SOURCE:/var/jenkins_home/nodeMonitors.xml C:\BCKJenkins\
docker cp JENKINS_CNT_SOURCE:/var/jenkins_home/jobs C:\BCKJenkins\
docker cp JENKINS_CNT_SOURCE:/var/jenkins_home/nodes C:\BCKJenkins\
docker cp JENKINS_CNT_SOURCE:/var/jenkins_home/plugins C:\BCKJenkins\
docker cp JENKINS_CNT_SOURCE:/var/jenkins_home/secrets C:\BCKJenkins\
docker cp JENKINS_CNT_SOURCE:/var/jenkins_home/users C:\BCKJenkins\
如果需要更改端口 (8081
)
编辑您的文件C:\BCKJenkins\jenkins.model.JenkinsLocationConfiguration.xml
<?xml version='1.1' encoding='UTF-8'?>
<jenkins.model.JenkinsLocationConfiguration>
<adminAddress>address not configured yet <nobody@nowhere></adminAddress>
<jenkinsUrl>http://localhost:8080/</jenkinsUrl>
</jenkins.model.JenkinsLocationConfiguration>
将文件插入目标容器
docker cp C:\BCKJenkins\config.xml JENKINS_CNT_TARGET:/var/jenkins_home/
docker cp C:\BCKJenkins\hudson.model.UpdateCenter.xml JENKINS_CNT_TARGET:/var/jenkins_home/
docker cp C:\BCKJenkins\hudson.plugins.git.GitTool.xml JENKINS_CNT_TARGET:/var/jenkins_home/
docker cp C:\BCKJenkins\jenkins.model.JenkinsLocationConfiguration.xml JENKINS_CNT_TARGET:/var/jenkins_home/
docker cp C:\BCKJenkins\jenkins.telemetry.Correlator.xml JENKINS_CNT_TARGET:/var/jenkins_home/
docker cp C:\BCKJenkins\nodeMonitors.xml JENKINS_CNT_TARGET:/var/jenkins_home/
docker cp C:\BCKJenkins\jobs JENKINS_CNT_TARGET:/var/jenkins_home/
docker cp C:\BCKJenkins\nodes JENKINS_CNT_TARGET:/var/jenkins_home/
docker cp C:\BCKJenkins\plugins JENKINS_CNT_TARGET:/var/jenkins_home/
docker cp C:\BCKJenkins\secrets JENKINS_CNT_TARGET:/var/jenkins_home/
docker cp C:\BCKJenkins\users JENKINS_CNT_TARGET:/var/jenkins_home/
递归更改所有权
docker exec --user=root JENKINS_CNT_TARGET bash -c "chown -R jenkins:jenkins $JENKINS_HOME"
或
docker exec -it --user=root JENKINS_CNT_TARGET bash
bash-5.0# chown -R jenkins:jenkins $JENKINS_HOME
重启目标容器
docker restart JENKINS_CNT_TARGET
检查端口冲突
为了避免与旧容器的端口冲突获取 Jenkins 的访问权限
Dashboard -> Manage Jenkins -> Configure System => Jenkins URL (update to new port).
假设我有一个容器在工作!!
这是我的 Dockerfile...
FROM jenkinsci/blueocean
USER root
RUN apk update && apk add wget
RUN wget --no-verbose -O /tmp/apache-maven-3.6.3-bin.tar.gz https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
RUN tar xzf /tmp/apache-maven-3.6.3-bin.tar.gz -C /opt/
RUN ln -s /opt/apache-maven-3.6.3 /opt/maven
RUN ln -s /opt/maven/bin/mvn /usr/local/bin
RUN rm /tmp/apache-maven-3.6.3-bin.tar.gz
RUN chown jenkins:jenkins /opt/maven;
ENV MAVEN_HOME=/opt/mvn
现在我创建了图像...
docker build -t jenkins/blueocean_ci --no-cache .
现在我 运行 我的容器...
docker run -p 8080:8080 -p 50000:50000 --name jenkinsblue jenkins/blueocean_ci
我做了很多更改...插件安装和管道...
哦,我忘记了什么(不管做什么)
然后我把jenkins目录解压到d:\Documents\JenkinsBCK\
...
docker cp jenkinsblue:/var/jenkins_home d:\Documents\JenkinsBCK\
我想在 Windows d:\Documents\JenkinsBCK\
上保存对之前特定文件夹位置的更改,我会重复使用它。
现在,我使用像卷一样引用该目录创建了另一个容器,更改了端口...
docker run -v d:\Documents\JenkinsBCK:/var/jenkins_home -p 8081:8080 -p 50001:50000 --name jenkins_cnt jenkins/blueocean_ci
现在,我正在尝试用我的旧东西测试我的新容器...
http://localhost:8081/
您是否再次要求输入密码位于 /var/jenkins_home/secrets/initialAdminPassword
? hhmmm 没问题...
docker exec jenkins_cnt bash -c "cat /var/jenkins_home/secrets/initialAdminPassword"
我以前配置的插件和管道在哪里?
怎么了?
怎么做?
检查 $JENKINS_HOME
变量的值
docker exec JENKINS_CNT_SOURCE env
PATH=/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=b1f58b975483
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_ALL=en_US.UTF-8
JAVA_VERSION=jdk8u292-b10
JAVA_HOME=/opt/java/openjdk
JENKINS_HOME=/var/jenkins_home
JENKINS_SLAVE_AGENT_PORT=50000
REF=/usr/share/jenkins/ref
JENKINS_VERSION=2.277.4
JENKINS_UC=https://updates.jenkins.io
JENKINS_UC_EXPERIMENTAL=https://updates.jenkins.io/experimental
JENKINS_INCREMENTALS_REPO_MIRROR=https://repo.jenkins-ci.org/incrementals
COPY_REFERENCE_FILE_LOG=/var/jenkins_home/copy_reference_file.log
MAVEN_HOME=/opt/mvn
HOME=/var/jenkins_home
检查 xml 个文件
docker exec JENKINS_CNT_SOURCE bash -c "ls -al /var/jenkins_home/*.xml"
-rw-r--r-- 1 jenkins jenkins 1600 May 5 00:09 /var/jenkins_home/config.xml
-rw-r--r-- 1 jenkins jenkins 156 May 5 00:09 /var/jenkins_home/hudson.model.UpdateCenter.xml
-rw-r--r-- 1 jenkins jenkins 370 May 4 21:07 /var/jenkins_home/hudson.plugins.git.GitTool.xml
-rw-r--r-- 1 jenkins jenkins 179 May 4 21:18 /var/jenkins_home/jenkins.model.JenkinsLocationConfiguration.xml
-rw-r--r-- 1 jenkins jenkins 171 May 4 21:07 /var/jenkins_home/jenkins.telemetry.Correlator.xml
-rw-r--r-- 1 jenkins jenkins 907 May 5 00:09 /var/jenkins_home/nodeMonitors.xml
从源容器中提取文件
docker cp JENKINS_CNT_SOURCE:/var/jenkins_home/config.xml C:\BCKJenkins\
docker cp JENKINS_CNT_SOURCE:/var/jenkins_home/hudson.model.UpdateCenter.xml C:\BCKJenkins\
docker cp JENKINS_CNT_SOURCE:/var/jenkins_home/hudson.plugins.git.GitTool.xml C:\BCKJenkins\
docker cp JENKINS_CNT_SOURCE:/var/jenkins_home/jenkins.model.JenkinsLocationConfiguration.xml C:\BCKJenkins\
docker cp JENKINS_CNT_SOURCE:/var/jenkins_home/jenkins.telemetry.Correlator.xml C:\BCKJenkins\
docker cp JENKINS_CNT_SOURCE:/var/jenkins_home/nodeMonitors.xml C:\BCKJenkins\
docker cp JENKINS_CNT_SOURCE:/var/jenkins_home/jobs C:\BCKJenkins\
docker cp JENKINS_CNT_SOURCE:/var/jenkins_home/nodes C:\BCKJenkins\
docker cp JENKINS_CNT_SOURCE:/var/jenkins_home/plugins C:\BCKJenkins\
docker cp JENKINS_CNT_SOURCE:/var/jenkins_home/secrets C:\BCKJenkins\
docker cp JENKINS_CNT_SOURCE:/var/jenkins_home/users C:\BCKJenkins\
如果需要更改端口 (8081
)
编辑您的文件C:\BCKJenkins\jenkins.model.JenkinsLocationConfiguration.xml
<?xml version='1.1' encoding='UTF-8'?>
<jenkins.model.JenkinsLocationConfiguration>
<adminAddress>address not configured yet <nobody@nowhere></adminAddress>
<jenkinsUrl>http://localhost:8080/</jenkinsUrl>
</jenkins.model.JenkinsLocationConfiguration>
将文件插入目标容器
docker cp C:\BCKJenkins\config.xml JENKINS_CNT_TARGET:/var/jenkins_home/
docker cp C:\BCKJenkins\hudson.model.UpdateCenter.xml JENKINS_CNT_TARGET:/var/jenkins_home/
docker cp C:\BCKJenkins\hudson.plugins.git.GitTool.xml JENKINS_CNT_TARGET:/var/jenkins_home/
docker cp C:\BCKJenkins\jenkins.model.JenkinsLocationConfiguration.xml JENKINS_CNT_TARGET:/var/jenkins_home/
docker cp C:\BCKJenkins\jenkins.telemetry.Correlator.xml JENKINS_CNT_TARGET:/var/jenkins_home/
docker cp C:\BCKJenkins\nodeMonitors.xml JENKINS_CNT_TARGET:/var/jenkins_home/
docker cp C:\BCKJenkins\jobs JENKINS_CNT_TARGET:/var/jenkins_home/
docker cp C:\BCKJenkins\nodes JENKINS_CNT_TARGET:/var/jenkins_home/
docker cp C:\BCKJenkins\plugins JENKINS_CNT_TARGET:/var/jenkins_home/
docker cp C:\BCKJenkins\secrets JENKINS_CNT_TARGET:/var/jenkins_home/
docker cp C:\BCKJenkins\users JENKINS_CNT_TARGET:/var/jenkins_home/
递归更改所有权
docker exec --user=root JENKINS_CNT_TARGET bash -c "chown -R jenkins:jenkins $JENKINS_HOME"
或
docker exec -it --user=root JENKINS_CNT_TARGET bash
bash-5.0# chown -R jenkins:jenkins $JENKINS_HOME
重启目标容器
docker restart JENKINS_CNT_TARGET
检查端口冲突
为了避免与旧容器的端口冲突获取 Jenkins 的访问权限
Dashboard -> Manage Jenkins -> Configure System => Jenkins URL (update to new port).