How to save & load Jenkins docker images in two hosts

This posts help you with step by step instructions to move jenkins images from one hosts to another hosts. I have personally used the below method and worked great for me.

I have another method mentioned here. But that gave me lot of errors and also the jenkins_home contents like custom shell scripts/job details etc were missed. But still I have posted because this can work for other docker containers.

Step 1: Save Jenkins Image in Machine 1

docker save jenkins > jenkins_bkup.tar

Step 2: Move the .tar file to Machine 2 from Machine 1

sudo scp -o StrictHostKeyChecking=no -i "my-docker-pair.pem" /home/ec2-user/jenkins_bkup.tar ec2-user@AWS_MACHINE_HOST:/home/ec2-user/jenkins_bkup.tar

Step 3: Docker Load in Host 2/Machine 2

cat jenkins_bkup.tar | docker load

Step 4: Run the Loaded image in Machine 2

sudo docker run --name czcjenkins -d -p 8080:8080 -p 50000:50000 -v /opt/czcjenkins:/var/jenkins_home jenkins

jenkins – this is the name of the jenkins image you have saved in the machine 1 (not the name of the tar)

Leave a Reply