Jenkins configuration file Backup:
Docker CP Focused_bhaskara:/var/jekins_home./jenkins_home
Where Focused_bhaskara is the name of the currently running Jenkins container and is available through Docker PS viewing names.
Docker create-v/var/jenkins_home--name JENKINS-DV
Make the data volume container and run:
1. Jenkins_home,copy the previously backed up Jenkins configuration directory to the current directory;
2. Edit Dockerfile as follows:
From Debian:jessie
volume/var/jenkins_home/
ADD jenkins_home//var/jenkins_home/
RUN echo "This is Jenkins data volume!"
Build Image:
Docker build-t JENKINSDV.
3. Build your own Jenkins Image,myjenk.
Dockerfile as follows:
From Jenkins:latest
USER Root
RUN apt-get update \
&& apt-get install-y sudo \
&& rm-rf/var/lib/apt/lists/*
RUN echo "Jenkins All=nopasswd:all" >>/etc/sudoers
#COPY apache-maven-3.3.9-bin.zip/var/jenkins_home/tools/hudson.tasks.maven_maveninstallation/maven3.3.9/
RUN echo "This is Jenkins data volume!"
Build Image:
Docker build-t Myjenk.
Start Myjenk for the first time (Dood the Docker Command takes effect):
Docker run-d--name mydockerjenk-v/var/run/docker.sock:/var/run/docker.sock-v $ (which Docker):/usr/bin/docker-p 8080 : 8080-p 50000:50000 Myjenk
4. As a result, we have two image, Myjenk and JENKINSDV, running the following command to complete the reuse of Jenkins:
Docker Run--name JENKINS-DV JENKINSDV
Docker run-d-P 8080:8080-p 50000:50000--volumes-from jenkins-dv--name myjenkins Myjenk
Note: If you start multiple Jenkins containers simultaneously and use the same--volumes-from parameter at the same time, they share this data volume and read and write to this data volume container, potentially causing unwanted results.
For example, we have a A, b two Jenkins container.
A first start and execute JOB1, build number 20.
when the B container is started, the B container job1 will show 20 builds. At this point B executes a job1 build, then B's JOB1 will have a total of 21 job1 builds from 1 to 21, and a only 20.
At this point a executes the JOB1 build again, then a can see build 22 without seeing build 21, because 21 is the build that B executes. Similarly, B does not see build 22.
To avoid this, you can open a data volume container again and allow B to load its volume boot.
Another way to do this is to delete the shared data volume container that has stopped running, so that each Jenkins container will re-create a separate volume for use, but it needs to be backed up (see the first part of this article).
Note: You cannot back up the latest changes by using the Docker commit command at this time!! See https://docs.docker.com/engine/reference/commandline/commit/
Backup and reuse of Jenkins Docker containers