Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins inside docker loses configuration when container is restarted

Tags:

docker

jenkins

I have followed the next guide https://hub.docker.com/r/iliyan/jenkins-ci-php/ to download the docker image with Jenkins.

When I start my container using docker start CONTAINERNAME command, I can access to Jenkins from localhost:8080.

The problem comes up when I change Jenkins configuration and restart Jenkins using docker stop CONTAINERNAME and docker start CONTAINERNAME, my Jenkins doesn't contain any of my previous configuration changes..

How can I persist the Jenkins configuration?

like image 939
Wildchild Avatar asked Dec 15 '22 06:12

Wildchild


1 Answers

You need to mount the Jenkins configuration as a volume, the -v flag will do just that for you. (you can ignore the --privileged flag in my example unless you plan on building docker images inside your jenkins docker image)

docker run --privileged --name='jenkins' -d -p 6999:8080 -p 50000:50000 -v /home/jan/jenkins:/var/jenkins_home jenkins:latest

The -v flag will mount your /var/jenkins_home outside your container in /home/jan/jenkins maintaining it between rebuilds.

--name so that you have a fixed name for the container to start / stop it from.

Then next time you want to run it, simply call

docker start jenkins
like image 63
Jan Vladimir Mostert Avatar answered Jan 22 '23 20:01

Jan Vladimir Mostert