How to Install Jenkins in a Docker Container

April 2, 2015 | By in LINUX HOWTO
| 4 Replies More

Hi all, today we'll learn how to install Jenkins using Docker. Jenkins is an award-winning application that monitors executions of repeated jobs, such as building a software project or jobs run by cron. It builds / tests software projects continuously. In a nutshell, Jenkins provides an easy continuous integration system, making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build. The automated, continuous build increases the productivity. It helps in monitoring executions of externally-run jobs, such as cron jobs and procmail jobs, even those that are run on a remote machine. Jenkins keeps the outputs and makes it easy for you to notice when something is wrong.

Docker is an Open Source project that provides an open platform to pack, ship and run any application as a lightweight container. It has no boundaries of Language support, Frameworks or packaging system and can be run anywhere, anytime from a small home computers to high-end servers. It makes them great building blocks for deploying and scaling web apps, databases, and back-end services without depending on a particular stack or provider.

Here are the quick and easy steps below on how we can install Jenkins CI in a Docker Container so that it facilitates us with Docker environment.

1. Installing Docker

First of all, we need to make sure that we have Docker installed in our host Operating System. To install, we'll need to the run the following command in a shell or terminal.

On Ubuntu

Package docker is available in Ubuntu's repository so, we'll be using apt manager to install it in sudo or root mode.

# apt-get install docker

On CentOS 7

On CentOS 7 machine, we'll use yum manager to install docker as it is also available in CentOS's repository.

# yum install docker

Installing Docker

2. Pulling Jenkins Image

After installing Docker in our host machine, we'll now go further towards installing Jenkins. We'll now pull Jenkins image from the Docker Registry Hub provided by zaiste. Before we pull the image using pull command, we'll need to protect our system as there is identified a malicious issue with pull command. To protect our system from this issue, we'll need to add into /etc/hosts entry. We can do using our favorite text editor.

# nano /etc/hosts

Now, add the following lines into it.

Adding host

Now, after we are protected from the malicious issue, we'll gonna start Docker Daemon. As we're running CentOS 7 in this tutorial, we'll use systemctl to start it.

# systemctl start docker

we'll now gonna pull our Jenkins image using the following command.

# docker pull

Pulling Jenkins Image

Now, we'll tag our image name with a short name to jenkins-image.

# docker tag jenkins-image

Tagging Jenkins Image

3. Running Jenkins Container

Next, we'll run a docker container using this image and map data directory from the container to the host. Here we map /var/lib/jenkins from the container to jenkins/ directory from the current path on the host. Jenkins port 8080 is also exposed to the host as 49001.

# docker run -d -p 49001:8080 -v $PWD/jenkins:/var/lib/jenkins -t jenkins-image

Running Jenkins Docker

4. Web Interface

As we have successfully run Jenkins Container, we can browse Jenkins Web Interface using our Web Browser by pointint to http://ip-address:49001 or http://localhost:49001 according to the configuration.

Jenkins Dashboard

Security Issue

In the default configuration, Jenkins does not perform any security check which allows any person accessing the site can configure Jenkins and jobs, and perform builds. While this configuration is acceptable during initial evaluation of the software, Jenkins should be configured to authenticate users and enforce access control in most other situations, especially when exposed to the Internet.

Now, we'll go for some security measure, we'll add username and password. We'll go to Manage Jenkins > Configure Global Security and select the "Enable Security"check box. For basic username/password authentication, I would recommend selecting "Jenkins Own User Database" for the security realm and then we'll select "Logged in Users can do anything". Now, to add a new username and password, goto Manage Jenkins > Manage Users>Create User. Then, we'll add details for our new users.

Fixed Security Issue


We have successfully installed Jenkins with Docker. Jenkins is an awesome tool for monitoring automation builds. It can be used for production of large scaled projects to small projects as it helps to increases the productivity. And Docker adds this tool a great platform for easy deploy and use of it. If you have any questions, suggestions, feedback please write them in the comment box below so that we can improve and update our contents. Thank you ! Enjoy :-)


Share This :

Free Linux Ebook to Download

Comments (4)

Trackback URL | Comments RSS Feed

  1. Karl Katzke says:

    Sadly, this is an incomplete tutorial -- for example, you didn't say anything about running slaves and how the slaves contact the master.

    • Arun Pyasi says:

      Hi Karl,
      Thanks for your precious comment. Yes, I haven't mentioned anything about running slaves as this tutorial is specfic for the installation of Jenkins in a Docker Container. If you want us to write more further specific on Jenkins, we'll write on it further in near future.

  2. ak says:

    Thanks a lot for this post,
    but I have a major issue with this method,
    I always get:-

    fatal: Could not read from remote repository.

    Please make sure you have the correct access rights
    and the repository exists.

    always when i try to add a repo to a new project in jenkinds.
    Could you explain me why, OR does this method require any prerequisite permissions or users in the linux?

    All helps appreciated.

    • Arun Pyasi says:


      I assume you have issue with the repository. What repository did you try to add in the project ? Can you share us an screenshot or what exactly you did while adding the repository?

      Make sure you have full rights on adding the repository.

      Thanks !

Leave a Reply

Commenting Policy:
Promotion of your products ? Comment gets deleted.
All comments are subject to moderation.