Backup i docker for jenkins

Hi , Am running jenkins through docker, if i stop the container then am loosing all the data. Again if i start it is loading from beginning,whats the backup strategy for this.

Quick reply is highly appreciated.

Take a look at the docs for the Jenkins image, the second example

docker run -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts

already shows how to create a volume with persistent data.

Hey tekki, i have started with this command only. my query is that when i want to stop that container all the data will be lost,but if i want to retrieve that data then what shall i do. how do i restart the container with old data

The data from /var/jenkins_home is saved in the volume jenkins_home, if you attach it to the new container it will be here again.

Hi Tekki,

Thanks for the answer, but if i type docker volume ls command then i am unable to find this volume(jenkins_home) where to check exactly

Try it like this:

$ docker run -d -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts
13e7bee2365b15e8e8...

$ docker container ls
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                              NAMES                                                                             13e7bee2365b        jenkins/jenkins:lts   "/sbin/tini -- /usr/…"   8 seconds ago       Up 3 seconds        0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp   jolly_sutherland

$ docker volume ls                                                                                      DRIVER              VOLUME NAME
local               jenkins_home

$ docker container stop 13e7
13e7

$ docker volume ls
DRIVER              VOLUME NAME
local               jenkins_home

Hey tekki, thanks for your valuable support. In jenkins scripted pipeline i am trying to upload the artifacts to nexus, but i am facing error while connecting it to the host.

ERROR: Failed to deploy artifacts: Could not transfer artifact net.java:cargo-tracker:war:1.0 from/to cargotracker (http://192.168.1.24:8081/repository/cargotracker): No route to host (Host unreachable)

Can u pls also help me in this regard …

Tekki, the solution which you have provided workd well for me, but how about the above error. can u please expedite this also…

If you are 100 % sure that the URL is correct please open a new question.