How to Setup Jenkins Using Docker With a Host Mount

To persist jenkins configurations, you need to create a directory in the host and mount it to the jenkins container.

You might Like:Complete Docker Course For DevOps From a Docker Captain

Follow the steps given below for setting up jenkins using docker.

  1. Create a home directory for Jenkins in the host.

     sudo mkdir /opt/jenkins_home
    
  2. Make jenkins container user as the owner of the jenkins_home directory using its UUID.

     sudo chown -R 1000:1000 /opt/jenkins_home
    
  3. Run the latest jenkins container using the following command.

     docker run  -d -p 8080:8080 -p 50000:50000 -v /your/home:/var/jenkins_home jenkins
    

Now you will be able to access jenkins on host port 8080.