eLearner
eLearner

Reputation: 85

Build jenkins image in docker

Whenever I run:

docker run -p 8080:8080 -p 50000:50000 jenkins/jenkins

I lose all the changes I made to the jenkins image in a previous session and it always creates a new image. Can some one please let me know why is this happening?

Upvotes: 0

Views: 106

Answers (1)

lvthillo
lvthillo

Reputation: 30851

If you want to create your custom Docker image you can write your own Dockerfile:

FROM jenkins/jenkins
COPY ...
RUN ...

The above is useful when you want to install different tools on your container or update configs which are not really Jenkins related.

All the jenkins related stuff is inside the directory /var/jenkins_home inside your container (job configurations, workspace, ...)

If you want to persist this data you can try the following:

Create a named Docker volume and mount the data from your container inside the volume. This is the preferred way to do it for Docker.

$ docker volume create my-jenkins-volume
$ docker run -d -p 8080:8080 -v my-jenkins-volume:/var/jenkins_home/ -p 5000:5000 jenkins/jenkins

Now you can delete your container and the data will still exist in the volume. You can start your container again with the same command and all your previous configurations will be loaded.

If you want to "save" you changes inside a new image you can use docker commit but this is often not the preferred way to get things done.

Upvotes: 1

Related Questions