# Part 1 – Install Jenkins with Docker

### Jenkins CI/CD Series

| Part | Article |
| --- | --- |
| 1 | [Install Jenkins with Docker](https://ask-abhi.com/part-1-install-jenkins-with-docker) |
| 2 | [Creating Your First Jenkins Pipeline](https://ask-abhi.com/part-2-creating-your-first-jenkins-pipeline) |
| 3 | [Jenkins SSH Remote Execution](https://ask-abhi.com/part-3-jenkins-ssh-remote-execution) |
| 4 | [Automating MySQL Backup to AWS S3](https://ask-abhi.com/part-4-automating-mysql-backup-to-aws-s3) |
| 5 | [Making Jenkins Automation Scalable](https://ask-abhi.com/part-5-making-jenkins-automation-scalable) |
| 6 | [Running Ansible from Jenkins](https://ask-abhi.com/part-6-running-ansible-from-jenkins) |
| 7 | [Jenkins Pipeline from GitHub](https://ask-abhi.com/part-7-control-jenkins-pipeline-through-github) |
| 8 | [Multibranch Pipelines](https://ask-abhi.com/part-8-multibranch-pipelines) |
| 9 | [Parameterized Pipelines](https://ask-abhi.com/part-9-parameterized-pipelines) |
| 10 | [Environment Variables in Pipelines](https://ask-abhi.com/part-10-environment-variables-in-pipelines) |

> This Part 1 base requirement for rest of the series parts

### Goal

The goal of this project is to install **Jenkins using Docker** and create a fully functional Jenkins environment that can be used for building CI/CD pipelines. By the end of this exercise, Jenkins will be running inside a Docker container and accessible through a web browser.

This setup provides a clean and reproducible environment for Jenkins, making it easy to deploy, manage, and upgrade without directly installing Jenkins on the host operating system.

### Purpose

The purpose of this exercise is to introduce the **foundation of Jenkins-based CI/CD environments** by containerizing Jenkins using Docker. Running Jenkins inside a container ensures portability, easier management, and better isolation from the host system.

This approach is widely used in modern DevOps environments because it allows teams to quickly spin up Jenkins instances, maintain persistent data using volumes, and scale automation infrastructure efficiently.

Through this project, we will:

*   Install Docker and configure the Docker repository
    
*   Pull the official Jenkins image from Docker Hub
    
*   Deploy Jenkins using **Docker Compose**
    
*   Configure persistent storage for Jenkins data
    
*   Access the Jenkins web interface and complete the initial setup
    

This forms the **starting point for the Jenkins CI/CD Mastery series**, where the Jenkins instance created in this step will be used for building pipelines, automating tasks, and integrating with other tools in later projects.

### Prerequisites

Prepare Host Linux machine locally on Windows/Mac ([Refer](https://ask-abhi.com/building-a-kubernetes-cluster-on-a-laptop-using-kubeadm-virtualbox-and-vagrant)), or on any Cloud

> Pro-Tip: Recommended on AWS:EC2, Stop the EC2 instance whenever finish the task

### Step-by-Step Implementation

Run the following command to uninstall all conflicting packages in case you are using any existing Linux system

```plaintext
sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-compose-v2 docker-doc podman-docker containerd runc | cut -f1)
```

### **Install using the** `apt` **repository**

Before you install Docker Engine for the first time on a new host machine, you need to set up the Docker `apt` repository. Afterward, you can install and update Docker from the repository.

*   **Set up Docker's** `apt` **repository.**
    

Add Docker's official GPG key:

```plaintext
sudo apt update
sudo apt install ca-certificates curl sudo install -m 0755 -d /etc/apt/keyrings sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc sudo chmod a+r /etc/apt/keyrings/docker.asc
```

Add the repository to Apt sources:

```plaintext
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF Types: deb URIs: https://download.docker.com/linux/ubuntu Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") Components: stable Signed-By: /etc/apt/keyrings/docker.asc EOF
```

```plaintext
sudo apt update
```

* * *

### Install the Docker packages.

To install the latest version, run:

```console
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
```

> **Note**
> 
> The Docker service starts automatically after installation. To verify that Docker is running, use:

```plaintext
sudo systemctl status docker
```

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/e7f454d6-5677-4976-9665-66e18a90f41b.png align="center")

> Some systems may have this behavior disabled and will require a manual start:

```plaintext
 sudo systemctl start docker
```

* * *

### Download Jenkins Image

It will have all the required configurations

```plaintext
sudo docker pull jenkins/jenkins
```

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/8f485107-a89a-4203-8531-f21f28940b5b.png align="center")

*   **Navigating/creating folder structure** `home/jenkins/jenkins_home#`
    

**Create** `docker-compose.yml`

```yaml
services:
  jenkins:
    container_name: jenkins
    image: jenkins/jenkins
    ports:
      - "8080:8080"
    volumes:
      - $PWD/jenkins_home:/var/jenkins_home
    networks:
      - net
networks:
  net:
```

*   **Create another folder that is mentioned in the YAML above** `home/jenkins/jenkins_home`
    

**Give the permissions**

```plaintext
sudo chown 1000:1000 jenkins_home -R
docker compose up -d
docker ps
```

> Note - Alwasy run docker compose from directory where docker-compose.yml resides

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/8e42043f-51a8-4645-9172-7b37b6c503b7.png align="center")

> Pro Tips - Check the logs. `docker logs -f jenkins`

*   **Access by using "host\_IP:8080."**
    

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/effbd585-e2eb-4fe8-95fb-74a3e5b19d48.png align="center")

*   **The password will be stored at** `/var/jenkins_home/secrets/initialAdminPassword`
    

* * *

### **Install Suggested Plugins**

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/80b41529-3836-4734-9a97-e59932ab48e5.png align="center")

*   **Create an admin user and go to the Home page**
    

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/7dbd94ff-4095-487a-9729-dffa8095e813.png align="center")

### **Done!!!**

* * *

### Conclusion:

In this first part of the **Jenkins CI/CD Mastery Series**, we successfully set up Jenkins using Docker, providing a clean and portable environment for running Jenkins without installing it directly on the host operating system. By containerizing Jenkins, we ensured that the setup is easy to manage, reproducible, and scalable for future CI/CD workloads.

We installed Docker, configured the Docker repository, pulled the official Jenkins image, and deployed Jenkins using **Docker Compose** with persistent storage. Finally, we accessed the Jenkins web interface and completed the initial setup by installing the suggested plugins and creating the administrator account.

This Jenkins instance will serve as the **foundation for the rest of the series**, where we will build real-world automation and CI/CD workflows.

In the next part, we will extend this environment by creating an **SSH-enabled remote server container** and integrating it with Jenkins. This will allow Jenkins to execute commands on remote systems — a key capability used in many DevOps automation pipelines.

* * *

### 🔗 Continue the Series

⬅️ **Previous Article:** [Home](https://ask-abhi.com)  
➡️ **Next Article:** [Part 2 **Creating Your First Jenkins Pipeline**](https://ask-abhi.com/part-2-creating-your-first-jenkins-pipeline)

* * *

⭐ If you found this article useful, follow **https://ask-abhi.com** for more DevOps tutorials.

* * *
