Jenkins is an free and open-source automation server that helps automate various tasks related to building, testing, and deploying software applications. It provides a platform for continuous integration (CI) and continuous delivery (CD), allowing developers to automate the process of building, testing, and deploying code changes to production environments.
Docker Compose is a tool for defining and running multi-container Docker applications. It allows you to define an entire application stack, including services, networks, and volumes, in a single file called docker-compose.yml. With a single command, you can then spin up your entire application stack, simplifying the process of managing and deploying multi-container Docker applications.
Prerequisites
- Up and running ubuntu 22.04 LTS machine.
- Basic knowledge in linux commands.
- Internet connectivity.
- Docker and docker compose should installed on your machine.
To install Docker and docker compose on ubuntu 22.04 LTS, We can use the given link.
In this post, We will deploy Jenkins CI CD Server using Docker Compose on Ubuntu 22.04 LTS Debian machine.
Step 1: Creating docker-compose.yml
To deploy Jenkins using Docker Compose, you’ll need to create a docker-compose.yml
file that describes the services, networks, and volumes for your Jenkins setup. Below is a basic example to get you started:
To create a docker-compose.yml
sudo nano docker-compose.yml
Copy and paste the followings configuration.
version: '3'
services:
jenkins:
image: jenkins/jenkins:lts
container_name: jenkins
ports:
- "8080:8080"
- "50000:50000"
volumes:
- jenkins_home:/var/jenkins_home
networks:
- jenkins-net
networks:
jenkins-net:
volumes:
jenkins_home:
This Docker Compose file:
- Uses the official Jenkins LTS image.
- Maps ports 8080 and 50000 to the host machine.
- Creates a Docker volume named jenkins_home to persist Jenkins data.
- Defines a custom network named jenkins-net for communication between services.
Save the docker-compose.yml
file.
Step 2: Deploy Jenkins Container
In the directory where your docker-compose.yml
file is located, run the following command to start the Jenkins container:
sudo docker-compose up -d
The -d
flag runs the containers in the background, It will take few sec or mins to pull the image and deploy the Jenkins.
Step 3: Validate the Container
To check the running containers launched by Docker Compose, you can use the following command:
sudo docker-compose ps
This command provides a summary of the status of each service defined in your docker-compose.yml
file. It shows information such as the service name, container ID, status, ports, and names.
Step 4: Logging
Some time we need to also check the real time logs, So we can use the given commands.
sudo docker-compose logs -f jenkins
Step 5: Accessing Jenkins
Access Jenkins by opening your web browser and navigating to http://localhost:8080.
Retrieve the initial admin password by running:
docker exec -it jenkins cat /var/jenkins_home/secrets/initialAdminPassword
Copy the password and paste it into the Jenkins web setup wizard.
Conclusion
We have successfully deployed Jenkins CI CD Automation server on docker’s container using docker compose on ubuntu 22.04 LTS Debian machine, If you still have questions, please post them in the comments section below.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
🙂