How to deploy your own Jenkins Instance?
Hi there and welcome back to my blog! Today we will be looking into how you can setup your own Jenkins instance on your development machine that you could use to practice and play around with Jenkins.
For this excercise, we will need to have the following prerequisites:
- A development machine with docker installed
- Some basic knowledge on how to run containers using a compose file.
Deploying containerized Jenkins
On your development machine, ensure that docker is installed. Now create a new file called Dockerfile
and add the following contents:
FROM jenkins/jenkins:2.289.3-lts-jdk11
USER root
RUN apt-get update && apt-get install -y apt-transport-https \
ca-certificates curl gnupg2 \
software-properties-common
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
RUN apt-key fingerprint 0EBFCD88
RUN add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) stable"
RUN apt-get update && apt-get install -y docker-ce-cli
USER jenkins
RUN jenkins-plugin-cli --plugins "blueocean:1.24.7 docker-workflow:1.26"
Create another file called docker-compose.yml
and add the following contents:
version: "3.6"
services:
my-jenkins:
image: jenkins-blueocean
build:
context: .
dockerfile: Dockerfile
environment:
- DOCKER_CERT_PATH=/certs/client
- DOCKER_TLS_VERIFY=1
ports:
- "8080:8080"
- "50000:50000"
volumes:
- ./jenkins-data/:/var/jenkins_home
- ./jenkins-docker-certs/:/certs/client:ro
Once you have these two files in place, lets build the container and kick it off. Run the following commands:
- Create the directories to store your jenkins data files suing the command:
mkdir ./jenkins-data; mkdir ./jenkins-docker-certs
- Build the contianer using
docker-compose build
. - Kick off the container using
docker-compose up
.
Once you have your container up and running, use the following post installation setup guide in order to complete the installation of jenkins.
You can now access Jenkins on your local machine as localhost:8080
.
NOTE:
- You need to run this as docker-compose up without -d option for detached mode because you will need to retrieve the AdminPassword for Jenkins from the docker logs. If you don't then you will need to retrieve this from
/var/jenkins_home/secrets/initialAdminPassword
at container run time.- The jenkins instance is a standalone node without a distributed master - worker deployment setup.
- You will notice that the compose file exposes port 50000. This is exposed in order for the jenkins server to listen to other Jenkins agent to connect to it in a distributed jenkins deployment. HTTP requests at this port get a minimal plain text response with some diagnostic information. It looks like the following:
Jenkins-Agent-Protocols: JNLP4-connect, Ping Jenkins-Version: 2.289 Jenkins-Session: b4783dfa Client: 172.17.0.1 Server: 172.17.0.3 Remoting-Minimum-Version: 3.14
- List of currently enabled TCP inbound agent protocols.
- The current version of Jenkins.
- The session of the current Jenkins execution. This is unrelated to web session cookies. This is changed to a new value whenever Jenkins starts. It is used in various URLs to help implement caching of static resources, and can be used by clients to tell whether Jenkins restarted.
- The client IP address as seen from Jenkins.
- The Jenkins controller’s IP address.
- The minimum required version of the Remoting library for agents to connect to this Jenkins controller.
- Inbound agents may instead be configured to use WebSocket transport to connect to Jenkins. In this case no extra TCP port need be enabled and no special security configuration is needed.
If you reached the end of this post, congratulations! You now have your very own containerized Jenkins Instance that you can play with. ☺️