Jenkins is an open source automation server used to automate repetitive tasks that are often encountered in continuous integration and delivery of software. In this guide, we will see how you can run Jenkins server on a Docker container managed via Systemd init system.

If you would prefer running Jenkins on a CentOS 7 or Ubuntu 18.04 instance, use the following guides instead.

How to Install Jenkins on Ubuntu

Install Jenkins Server Stable on CentOS 7

Install Jenkins Server on CentOS 8

This guide is specific for Docker guys who like containerizing applications and any infrastructure management tools.

Running Jenkins Server in Docker – Dependencies

Running Jenkins Server on a Docker has few dependencies that you’ll need to satisfy.

  • Linux or macOS
  • Docker Engine installed and running
  • A user account with sudo privileges

Step 1: Install Docker Engine

Start by installing Docker engine on your base operating system. You can use our previous guide for docker installation.

How to install Docker CE on Ubuntu / Debian / Fedora / Arch / CentOS

After the installation, you can confirm the version installed by running:

$ docker version
 Version:           18.06.1-ce
 API version:       1.38
 Go version:        go1.10.3
 Git commit:        e68fc7a
 Built:             Tue Aug 21 17:24:51 2018
 OS/Arch:           linux/amd64
 Experimental:      false

  Version:          18.06.1-ce
  API version:      1.38 (minimum version 1.12)
  Go version:       go1.10.3
  Git commit:       e68fc7a
  Built:            Tue Aug 21 17:23:15 2018
  OS/Arch:          linux/amd64
  Experimental:     false

Step 2: Add jenkins user

Next is to add Jenkins system user to your server. This user will manage Jenkins service.

sudo groupadd --system jenkins
sudo useradd -s /sbin/nologin --system -g jenkins jenkins
sudo usermod -aG docker jenkins

Ensure this user is added to the docker group.

# id jenkins
uid=999(jenkins) gid=998(jenkins) groups=998(jenkins),999(docker)

Pull the LTS docker image release of Jenkins

sudo docker pull jenkins/jenkins:lts

Confirm that the image download was successful.

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
jenkins/jenkins     lts                 9cff19ad8c8b        3 weeks ago         730MB

Step 3: Create a Jenkins Data directory & container

We need a persistent storage for Jenkins data to ensure that the data is made to remain intact and can, therefore, be re-used in the event that the container shuts down or crashes.

sudo mkdir /var/jenkins
sudo chown -R 1000:1000 /var/jenkins

Step 4: Create a Jenkins Container Systemd service

Create a new systemd service unit file for Jenkins.

sudo vim /etc/systemd/system/jenkins-docker.service


Description=Jenkins Server

ExecStartPre=-/usr/bin/docker kill jenkins-server
ExecStartPre=-/usr/bin/docker rm jenkins-server
ExecStartPre=/usr/bin/docker pull jenkins/jenkins:lts
ExecStart=/usr/bin/docker run \
          --name jenkins-server \
          --publish 8080:8080 \
          --publish 50000:50000 \
          --volume /var/jenkins:/var/jenkins_home \
ExecStop=/usr/bin/docker stop jenkins-server


Reload systemd and start jenkins service

sudo systemctl daemon-reload
sudo systemctl start jenkins-docker

On checking the status, you should get a running message.

$ systemctl status jenkins-docker
* jenkins-docker.service - Jenkins Server
   Loaded: loaded (/etc/systemd/system/jenkins-docker.service; disabled; vendor preset: enabled)
   Active: active (running) since Wed 2018-10-31 15:32:59 PDT; 6min ago
 Main PID: 24964 (docker)
    Tasks: 11 (limit: 1111)
   CGroup: /system.slice/jenkins-docker.service
           `-24964 /usr/bin/docker run --privileged --name jenkins-server --publish 80:8080 --publish 50000:50000 --volume /var/jenkins:/var/jenkins_h

Oct 31 15:33:23 ubuntu-01 jenkins[24964]: INFO: Obtained the updated data file for hudson.tasks.Maven.MavenInstaller
Oct 31 15:33:23 ubuntu-01 jenkins[24964]: Oct 31, 2018 10:33:23 PM hudson.model.AsyncPeriodicWork$1 run
Oct 31 15:33:23 ubuntu-01 jenkins[24964]: INFO: Finished Download metadata. 13,352 ms
Oct 31 15:33:25 ubuntu-01 jenkins[24964]: Oct 31, 2018 10:33:25 PM hudson.model.UpdateSite updateData
Oct 31 15:33:25 ubuntu-01 jenkins[24964]: INFO: Obtained the latest update center data file for UpdateSource default
Oct 31 15:33:25 ubuntu-01 jenkins[24964]: Oct 31, 2018 10:33:25 PM jenkins.InitReactorRunner$1 onAttained
Oct 31 15:33:25 ubuntu-01 jenkins[24964]: INFO: Completed initialization
Oct 31 15:33:25 ubuntu-01 jenkins[24964]: Oct 31, 2018 10:33:25 PM hudson.WebAppMain$3 run
Oct 31 15:33:25 ubuntu-01 jenkins[24964]: INFO: Jenkins is fully up and running

Step 5: Unlock Jenkins Server installation

Browse to the URL to access web installation wizard:


When you first access a new Jenkins instance, you are asked to unlock it using an automatically generated password.

unlock jenkins centos7 min

Get the password from

# cat /var/jenkins/secrets/initialAdminPassword 

Copy-paste the automatically-generated alphanumeric password into the Administrator password field and click Continue.

In the next page, install recommended plugins or plugins that suit your desired Jenkins usage. if not sure, select installation of recommended plugins.

jenkins install plugins min

Next is to create an admin user account used to manage the Jenkins server.

install jenkins centos7 set admin account min

After a successful installation, you’ll get to Jenkins Management console.

install jenkins arch linux 02 min

Enjoy automating your jobs with Jenkins. For more reading, check Official Documentation.

Recommended Udemy Courses To Learn Jenkins:

Also check:

How to Manage Users and Roles in Jenkins

Configure Jenkins behind Nginx reverse proxy and Let’s Encrypt SSL

How to Configure Jenkins FreeIPA LDAP Authentication

Your support is our everlasting motivation,
that cup of coffee is what keeps us going!

As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.


Please enter your comment!
Please enter your name here