Usual practice is to not try to "move" or "save" or "export" or "commit" containers. Just create a new container on the new machine.
For this to work you need to store all of the critical data your container needs outside the container. The Jenkins image documentation discusses this. It has a strong recommendation for using named volumes, which are harder to manage in several ways; the Docker documentation on backing up named volumes is relevant to this.
I'll assume you've created a named volume to hold the content. If you haven't, the Jenkins Dockerfile declares a VOLUME
so there should be an anonymous volume holding the Jenkins home directory. I'd look for its volume ID using docker volume ls
or docker inspect
and try using that.
# when you initially started Jenkins; copied from
# https://github.com/jenkinsci/docker/blob/master/README.md
docker run \
-p 8080:8080 -p 50000:50000 \
-v jenkins_home:/var/jenkins_home \
jenkins/jenkins:lts
You need to export the data from the volume. (docker stop
Jenkins might be a good idea first.) You can use a temporary container to do this:
docker run \
--rm \
-v jenkins_home:/jenkins_home \
-v $PWD:/export \
-w /jenkins_home \
busybox \
tar cf /export/jenkins_home.tar .
gzip jenkins_home.tar
scp jenkins_home.tar.gz elsewhere:
Now you've gotten the data the container needs on to the remote host. You need to recreate the data volume:
ssh elsewhere
gunzip jenkins_home.tar.gz
docker run \
--rm \
-v jenkins_home:/jenkins_home \
-v $PWD:/import \
-w /jenkins_home \
busybox \
tar xf /import/jenkins_home.tar .
Now the remote host has a volume named jenkins_home
that has a copy of the exported data, and you can run the same Jenkins command you initially ran
ssh elsewhere
docker run \
-p 8080:8080 -p 50000:50000 \
-v jenkins_home:/var/jenkins_home \
jenkins/jenkins:lts
This approach keeps the application and its data separate. Since you're still using an unmodified upstream image, if there's ever a security issue and you need to upgrade Jenkins, you can docker pull jenkins/jenkins:lts
to get a newer version and restart the container.
docker commit
is almost never a best practice. Say you do need to update Jenkins; if you committed an image as in the question, you need to remember exactly what you did to create the image and repeat it, but the nature of a committed image is that there's no record of this. If a custom image is useful for your application, write a Dockerfile for it and commit it to source control. Also note that docker commit
doesn't include volume content and the actual data you want to preserve is always in a volume (possibly anonymous) so the approach you're proposing in the question won't bring across the data you need anyways.