Kedar Kulkarni
Kedar Kulkarni

Reputation: 95

How to configure Jenkins in Docker?

I'm new to Jenkins and Docker both. I am currently working on project where I allow users to submit jobs to jenkins. And I was wondering if there is a way to use docker to dynamically spun-up Jenkins server and redirect all the user jobs coming from my application to this server and then destroy this jenkins once the work is done. Is it possible? if yes, how ? if no, Why? Also, I need to setup maven for this jenkins server, do I need another container for that?

Upvotes: 2

Views: 453

Answers (1)

lvthillo
lvthillo

Reputation: 30851

You can try the following but I can't guarantee if it's that easy to move your jenkins content from your dedicated server to your docker container. I did not try it before .

But the main thing is the following.

  • Create a backup of the content of your dedicated jenkins server using tar
  • Create a named docker volume:

    $ docker volume create --name jenkins-volume
    
  • Extract your jenkins-backup.tar inside your docker volume. This volume is in /var/lib/docker/volumes/jenkins-volume/_data

    $ sudo tar -xvpzf jenkins-backup.tar -C /var/lib/docker/volumes/jenkins-volume/_data/
    
  • Now you can start your jenkins container and telling it to use the jenkins-volume. Use the jenkins-image which is the same version as the dedicated jenkins.

    $ docker run -d -u jenkins --name jenkins -p 50000:50000 -p 443:8443 -v jenkins-volume:/var/jenkins_home --restart=always jenkins:your-version
    

For me this worked to move the content from our jenkins container on AWS to a jenkins container on another cloud provider. I did not try it for a dedicated server. But you can't break anything of your existing jenkins when you try it.

Upvotes: 1

Related Questions