However, Jenkins images declares the jenkins home directory (/var/jenkins_home) as a volume (See reference) so you cannot use the command docker commit to create the image as your changes made to Jenkins won't go with the image. You have to make a backup of your data volume instead (refer instructions on this page).
Here are the instructions to backup your Jenkins data from your Jenkins container (recently created from this blog), and how-to restore it:
Backup Jenkins Data Volume
1. Make sure your local drive is shared to your containers by selecting the drive you want to keep your back up file in Docker Settings. (You may need to enter your Windows account password)2. Use command docker run --rm --volumes-from <container> -v <local_path>:<container_path> ubuntu tar cvf <container_path>/jenkins_home.tar /var/jenkins_home to backup Jenkins data volume into a TAR file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
C:\Users\Chairat\jenkinsdemo>docker run --rm --volumes-from jenkinsdemo -v C:\Users\Chairat\jenkinsdemo:/backup ubuntu tar cvf /backup/jenkins_home.tar /var/jenkins_home |
3. Once complete, you will get a TAR file in your <local_path>
Now you can send this backup file to whoever you want.
Restore Jenkins Data Volume
1. Use command docker run -v /var/jenkins_home --name jenkinsdata ubuntu /bin/bash to create a new container with a new data volume
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
C:\Users\Chairat\jenkinsdemo>docker run -v /var/jenkins_home --name jenkinsdata ubuntu /bin/bash |
2. Use command docker ps -a you will see the new container has been created.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | |
d6f6b6e82592 ubuntu "/bin/bash" 7 days ago Exited (0) 3 seconds ago jenkinsdata | |
ad139a52c20e jenkins:1.651.3 "/bin/tini -- /usr/lo" 9 days ago Exited (143) 40 minutes ago jenkinsdemo | |
612835a9bf7f mariadb:10.1.17 "docker-entrypoint.sh" 9 days ago Exited (0) 40 minutes ago mariadb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
C:\Users\Chairat\jenkinsdemo>docker run --rm --volumes-from jenkinsdata -v C:\Users\Chairat\jenkinsdemo:/backup ubuntu bash -c "cd /var && tar xvf /backup/jenkins_home.tar --strip 1" |
Now, you have the Jenkins data volume restored from backup.
4. You can create a new Jenkins container using the restored data volume by using command docker run -d --volumes-from jenkinsdata --name jenkins2 -p 8081:8080 jenkins:1.651.3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
C:\Users\Chairat\jenkinsdemo>docker run -d --volumes-from jenkinsdata --name jenkins2 -p 8081:8080 jenkins:1.651.3 | |
e278421128ace35288e36de382d3902a7d813eb417a0ad3497d6e856e604054b |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
C:\Users\Chairat\jenkinsdemo>docker rm jenkinsdata | |
jenkinsdata |
Replaced console commands with Gist
ReplyDeletethanks for Providing a Good Information
ReplyDeleteanyone want to learn advance devops tools or devops online training visit:
DevOps Training
DevOps Online Training
DevOps Training institute in Hyderabad
DevOps Training in Ameerpet
Thank you for sharing very useful blog!!!!
ReplyDeleteKubernetes Online Training
Docker Online Training
Docker Training in Hyderabad
Kubernetes Training in Hyderabad