Docker & Jenkins Installation
Step1: Open a terminal and run the following command to update your package index:
sudo apt update
Step2: Installing the packages so that system can securely access repositories over HTTPS.
sudo apt install apt-transport-https ca-certificates curl software-properties-common
Here, package name is apt-transport-https
ca-certificates: verifies the authentication of HTTPS. The system needs to trust to the server while downloading the packages.
curl: It is a command line tool to transfer the data with URL. We will download Docker GPG key.
software-properties-common: It manages the repositories.
Once you run above command, you can able to access the Docker repository.
Step3: curl -fsSL https://download.docker.com/linux/ubnutu/gpg | sudo apt-key add -
curl -fsSL → f: Fail silently on server errors, -s: Silent mode, which suppress the progress output, -S: shows an error message, if it fails, -L: Follow redirects, if the URL is redirected to another location
https://download.docker.com/linux/ubnutu/gpg → Docker GPG key is hosted on this link. You need to fetch the key.
apt-key add - → Passes the curl output and gives an input to this command so that it adds the key to the system’s list.
I have run this command on my system but it didn’t work.
ubuntu@ip-172-31-25-118:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK
ubuntu@ip-172-31-25-118:~$ sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /usr/share/keyrings/docker.gpg → Download the GPG key ad save it into the appropriate directory.
Step4: sudo add-apt-repository “deb [arch=amd64] https://download.docker.com $(lsb_release -cs) stable”
add-apt-repository → adds a repository to the APT source.
This indicates the format for adding a new repository
deb → This indicates the repository that contains the binary packages.
[arch=amd64] → It specifies the architecture of package. amd64 refers to the 64 bit architecture which is common for modern systems.
$(lsb_release -cs) → It substitute the output of lsb_release -cs which returns the codename for Ubuntu distribution (eg, focal for Ubuntu 20.04, jammy for 22.04). This ensures that you will get the correct version of Docker as per your Ubuntu distribution.
stable → It specifies that you want the stable release of docker.
I have run the command but it gives an error
tee: It is a command that reads from standard input and write to both standard output and to the specified file.
sudo tee etc/apt/sources.list.d/docker.list → It saves the Docker repository in this location
ubuntu@ip-172-31-25-118:~$ echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list deb [arch=amd64] Output: https://download.docker.com/linux/ubuntu noble stable
Step5: sudo apt-get update
Step6: Install the Docker Community edition
sudo apt-get install docker-ce
Step 7: Verify the Docker version
ubuntu@ip-172-31-25-118:~$ docker --version
Output: Docker version 27.3.1, build ce12230
Step8: Verify the status of Docker
ubuntu@ip-172-31-25-118:~$ sudo systemctl status docker
● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; preset: e> Active: active (running) since Mon 2024-10-14 09:40:27 UTC; 1h 41min ago TriggeredBy: ● docker.socket Docs: https://docs.docker.com Main PID: 5758 (dockerd) Tasks: 9 Memory: 50.0M (peak: 50.2M) CPU: 771ms CGroup: /system.slice/docker.service └─5758 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/cont>
Installing Jenkins:-
Step1: You can install OpenJDK which is a popular version of java
sudo apt-get install openjdk-11-jdk
Step2: After the installation of java, verify the installation
ubuntu@ip-172-31-25-118:~$ java -version
openjdk version "11.0.24" 2024-07-16
OpenJDK Runtime Environment (build 11.0.24+8-post-Ubuntu-1ubuntu324.04.1)
Step3: Navigate a directory where you want to install Jenkins package.
ubuntu@ip-172-31-25-118:~/jenkins_setup$
Step4: Use wget to download the latest Jenkins .deb package
wget http://pkg.jenkins.io/debian-stable/binary/jenkins_2.387.1_all.deb
Step5: Once the download is complete, you’ll have a file named something like jenkins_2.387.1_all.deb in your current directory. Now, you can install it using dpkg command.
Note:- We need use to use dpkg command to install any packages in Debian
Step6: sudo systemctl start jenkins → Start the Jenkins
Step7: Check the status
ubuntu@ip-172-31-25-118:~/jenkins_setup$ sudo systemctl status jenkins
● jenkins.service - Jenkins Continuous Integration Server Loaded: loaded (/usr/lib/systemd/system/jenkins.service; enabled; preset: enabled) Active: active (running) since Mon 2024-10-14 14:06:50 UTC; 2min 24s ago Main PID: 10744 (java) Tasks: 36 (limit: 1078) Memory: 294.3M (peak: 300.7M) CPU: 1min 30.384s CGroup: /system.slice/jenkins.service └─10744 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/java/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8080
Eg: Write a script to automate start and stop the Jenkins and Docker services.
Code:
#!/bin/bash
echo "Enter the service you want to manage (docker/jenkins)"
read service
echo "Enter the action (start/stop)"
read action
sudo systemctl $action $service
echo "$service service $action completed"
Output: Consider the jenkin service is stopped
○ jenkins.service - Jenkins Continuous Integration Server
Loaded: loaded (/usr/lib/systemd/system/jenkins.service; enabled; preset: enabled) Active: inactive (dead) since Mon 2024-10-14 14:46:03 UTC; 35s ago Duration: 39min 12.527s Process: 10744 ExecStart=/usr/bin/jenkins (code=exited, status=143) Main PID: 10744 (code=exited, status=143) Status: "Jenkins stopped" CPU: 1min 33.706s
ubuntu@ip-172-31-25-118:~/scripts$ ./startstop.sh
Enter the service you want to manage (docker/jenkins)
jenkins
Enter the action (start/stop)
start
jenkins service start completed
ubuntu@ip-172-31-25-118:~/scripts$ sudo systemctl status jenkins
● jenkins.service - Jenkins Continuous Integration Server Loaded: loaded (/usr/lib/systemd/system/jenkins.service; enabled; preset: enabled) Active: active (running) since Wed 2024-10-16 14:02:41 UTC; 2min 32s ago Main PID: 1451 (java) Tasks: 36 (limit: 1078) Memory: 242.2M (peak: 273.9M) CPU: 34.746s CGroup: /system.slice/jenkins.service └─1451 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/java/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8080
We can also analyze the logs for Docker and Jenkins using journalctl command.
ubuntu@ip-172-31-25-118:~/scripts$ journalctl -u jenkins