How to Install Docker and Jenkins on Ubuntu Using Package Managers

Are you diving into the world of DevOps? Mastering tools like Docker and Jenkins is a crucial step toward building a seamless CI/CD pipeline. In this blog, I’ll walk you through how to install Docker and Jenkins on Ubuntu using package managers. Let's get started! 🛠️
Installing Docker on Ubuntu
Docker is a powerful containerization tool that enables you to create, deploy, and manage lightweight, portable applications. Follow these steps to install Docker:
Step 1: Update the Package Index
First, make sure your system is up-to-date by running:
sudo apt update
Step 2: Install Required Packages
Install the necessary packages for apt to communicate with external repositories over HTTPS:
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
Step 3: Add Docker’s GPG Key
Download and add Docker's official GPG key to ensure secure package downloads:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Step 4: Add Docker’s Repository
Replace <UBUNTU_VERSION> with your Ubuntu version (e.g., focal, jammy):
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Step 5: Update the Package Index Again
Refresh the package index to include the newly added Docker repository:
sudo apt update
Step 6: Install Docker
Install Docker Community Edition (CE) and its components:
sudo apt install -y docker-ce docker-ce-cli containerd.io
Step 7: Verify Docker Installation
Check if Docker is installed by running:
docker --version

Step 8 (Optional): Manage Docker as a Non-Root User
To avoid using sudo with Docker commands, add your user to the Docker group:
sudo usermod -aG docker $USER && newgrp docker
Log out and log back in for changes to take effect.
Step 9: Test Docker Installation
Run a test container to confirm Docker is working properly:
docker run hello-world

Installing Jenkins on Ubuntu
Jenkins is an open-source automation server widely used for CI/CD. Here’s how you can install it on your system:
Step 1: Install Java
Jenkins requires Java. Install OpenJDK 17 with the following commands:
sudo apt install openjdk-17-jre -y
java -version

Step 2: Install Dependencies
Install the required dependencies for Jenkins:
sudo apt-get install -y ca-certificates curl gnupg
Step 3: Add Jenkins GPG Key
Add the GPG key for Jenkins to your system:
curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null
Step 4: Add Jenkins Repository
Add the Jenkins repository to your system:
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null
Step 5: Update the Package Index
Refresh the package list to include the Jenkins repository:
sudo apt-get update
Step 6: Install Jenkins
Install Jenkins using the command:
sudo apt-get install jenkins -y
Step 7: Enable and Start Jenkins
Enable Jenkins to start automatically on boot and start the Jenkins service:
sudo systemctl enable jenkins

Step 8: Verify Jenkins Installation
Check the status of Jenkins to ensure it is running:
sudo systemctl status jenkins

Step 9: Verify Jenkins Installation in browser also

Conclusion
You’ve successfully installed Docker and Jenkins on your Ubuntu system! 🎉
Docker will help you containerize your applications, while Jenkins will streamline your CI/CD workflows. Combine these tools to create an efficient and scalable development environment.
What's Next?
Dive deeper into:
Setting up your first Jenkins pipeline.
Using Docker in Jenkins for automated builds.
Exploring advanced Docker networking and volumes.
Stay tuned for more DevOps tutorials. Got questions? Drop them in the comments below! 😊




