🚀 Day 7 : Mastering Package Managers: Installing Docker & Jenkins in Ubuntu and CentOS + Service Management
As part of my #90DaysOfDevOps journey with #TrainWithShubham, today's focus is on mastering package managers and learning how to manage system services using systemctl
! Let's dive into installing Docker and Jenkins on both Ubuntu and CentOS using package managers, explore how to manage services, and learn a few cool tasks to automate everything! 🛠️
🔍 What is a Package?
In simple terms, a package is a collection of files that help install an application on your system. It could be a command-line tool, a GUI application, or a software library required by other programs.
🤖 Package Managers
There are different package managers for different systems. For example:
For RPM (used in CentOS/RHEL), we use package managers like Yum or DNF.
For DEB (used in Ubuntu/Debian), we use apt or apt-get.
These package managers help in installing, updating, and managing software packages. Now, let's get started with installing Docker and Jenkins!
🐳 How to Install Docker and Jenkins in Ubuntu and CentOS
🟢 Installing Docker on Ubuntu:
Update your system:
sudo apt update
Install dependencies:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
Add Docker’s official GPG key and repository:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Install Docker:
sudo apt update sudo apt install docker-ce
Start Docker:
sudo systemctl start docker sudo systemctl enable docker
🔵 Installing Jenkins on Ubuntu:
Add the Jenkins repository:
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo tee \ /usr/share/keyrings/jenkins-keyring.asc > /dev/null sudo sh -c 'echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \ https://pkg.jenkins.io/debian-stable binary/ > \ /etc/apt/sources.list.d/jenkins.list'
Install Jenkins:
sudo apt update sudo apt install jenkins
Start Jenkins:
sudo systemctl start jenkins sudo systemctl enable jenkins
🟠 Installing Docker on CentOS:
Update your system:
sudo yum update -y
Install Docker:
sudo yum install docker -y
Start and enable Docker:
sudo systemctl start docker sudo systemctl enable docker
🔴 Installing Jenkins on CentOS:
Add the Jenkins repository:
sudo wget -O /etc/yum.repos.d/jenkins.repo \ https://pkg.jenkins.io/redhat-stable/jenkins.repo sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
Install Jenkins:
sudo yum install jenkins -y
Start and enable Jenkins:
sudo systemctl start jenkins sudo systemctl enable jenkis
🔧 Managing Services with systemctl
Once Docker and Jenkins are installed, you’ll often need to manage their services. Let’s look at some useful tasks:
🟡 Checking Docker Service Status:
sudo systemctl status docker
You’ll see the current status, whether Docker is running, stopped, or failed.
🔴 Managing Jenkins Service:
Stop Jenkins:
sudo systemctl stop jenkins
Check Jenkins Status:
sudo systemctl status jenkins
Stopping Jenkins will help if you need to perform updates or debug any issues. You can restart it with:
sudo systemctl start jenkins
🤖 Automating Service Management with a Script
Automation is key in DevOps! Here's a small script that starts or stops Docker and Jenkins based on user input:
#!/bin/bash
echo "What would you like to do? (start/stop/restart)"
read action
if [ "$action" == "start" ]; then
sudo systemctl start docker
sudo systemctl start jenkins
echo "Docker and Jenkins started!"
elif [ "$action" == "stop" ]; then
sudo systemctl stop docker
sudo systemctl stop jenkins
echo "Docker and Jenkins stopped!"
elif [ "$action" == "restart" ]; then
sudo systemctl restart docker
sudo systemctl restart jenkins
echo "Docker and Jenkins restarted!"
else
echo "Invalid action. Please use start, stop, or restart."
fi
Save this script, make it executable (chmod +x
scriptname.sh
), and now you have an automated way to manage services!
📄 Analyzing Logs with journalctl
To check what’s happening behind the scenes for Docker and Jenkins, we can use the journalctl
command:
# View Docker logs
sudo journalctl -u docker
# View Jenkins logs
sudo journalctl -u jenkins
This will give you valuable insights into errors, warnings, or other messages that can help you troubleshoot.
🚀 Enable and Disable Services on Boot
Enable Docker to start on boot:
sudo systemctl enable docker
Disable Jenkins from starting on boot:
sudo systemctl disable jenkins
Conclusion 🎯
Understanding how to install and manage services like Docker and Jenkins with package managers and
systemctl
is a foundational skill in the DevOps world. It’s empowering to see how much you can automate and control with just a few commands!I invite all my fellow learners and professionals to join me in this #90DaysOfDevOps challenge with #TrainWithShubham! Let’s learn, grow, and build amazing skills together! 🌱💻
#DevOps #Linux #Docker #Jenkins #Automation #Systemctl #90DaysOfDevOps #TrainWithShubham
Subscribe to my newsletter
Read articles from Chintamani Tare directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Chintamani Tare
Chintamani Tare
👨💻 Chintamani Tare | DevOps Enthusiast & Linux Advocate 🌐 I'm a passionate DevOps engineer with a solid foundation in Linux system administration. With a deep interest in automation, cloud technologies, and CI/CD pipelines, I love simplifying complex tasks and building scalable infrastructure. Whether it's scripting in Bash, managing servers with Ansible, or deploying applications with Docker and Kubernetes, I'm always eager to explore the latest tools and practices in the DevOps space.