Jenkins as a Container

Running Jenkins in a Container

Published on Dec 28, 2020

Reading time: 2 minutes.


Run jenkins as a container with the stateful volume!

Why Jenkins as a container ๐Ÿค”

  • It’s helps simplify the installation process.
  • Decrease dependency errors.
  • The Turnaround time for an Jenkins server installation is just few minutes.
  • Cross platform compatible.

Why do we need a stateful volume!๐Ÿคจ

  • Containers are often an ephemeral where in Jeknins we need to save our workloads even if we are not using it regularly. As in we will setting up the users, credentials inside Jenkins so it is important to save this as a stateful volume.

Let’s get started! ๐ŸŽฌ

Create the volume for Jenkins on Docker host.


# docker volume create jenkins-data 

To check and confirm if the volume is created for us

 # docker volume ls
 DRIVER              VOLUME NAME
 local               jenkins-data

Execute the following command to run the jenkins as a container.

    docker run --name klnjenkins \
    --rm --detach \
    --publish 8080:8080 \
    --publish 50000:50000 \
    --volume jenkins-data:/var/jenkins_home \
    jenkins/jenkins:lts
Command Usage
–name name of the container
–rm Automatically removes the Docker container (the instance of the Docker image) when it is shut down.
–publish Exposes the Docker daemon port on the host machine
–volume Maps the /var/jenkins_home directory inside the container to the Docker volume named jenkins-data.
–detach Runs the Docker container in the background

Note: We have exposed our 8080 port to assess our Jenkins server modify if you want to use different port.


  • Open your browser and with docker host machine ip or localhost:8080 if it’s a localhost. You will be seeing an unlock jenkins screen like below.

N|Solid

  • To get our intialadmin password, you can grab it from the docker container logs.
docker logs klnjenkins

N|Solid

  • Now copy the password and paste it on the browser and continue the installation with the suggested plugins as below, if you are beginner level user of jenkins

N|Solid

  • Create the user along with password if you want a separate user for jenkins server else skip and use as admin. Remember, admin user will not have password by default but you can set it later from inside via manage jenkins.

  • We are all set now!๐Ÿฅ jenkins is ready to use via docker container ๐Ÿฅ‚.

N|Solid

How to confirm if our state of the works of persisted? ๐Ÿ™‹๐Ÿฝโ€โ™‚๏ธ

  • Create any hello world job with some name.
  • Kill the docker container of jenkins.

Now run the container with the command as above

    docker run --name klnjenkins \
    --rm --detach \
    --publish 8080:8080 \
    --publish 50000:50000 \
    --volume jenkins-data:/var/jenkins_home \
    jenkins/jenkins:lts
  • Now we can assess the jenkins via the same ip:port with the previously created credentials and we can see our pipeline jobs persisted! ๐Ÿคฉ๐ŸŽ‰๐ŸŽ‰