Prateek Tomar
Posted on July 1, 2024
Welcome to the comprehensive guide on installing Jenkins on Docker. Jenkins is a open source automation server that helps in building, deploying, and automating projects.
Docker simplifies the process by providing a consistent environment across multiple systems. Let's deep dive into the process of setting up Jenkins on Docker.
Prerequisites
Before we begin, make sure you should have the following installations.
- Docker Installed: Ensure docker is installed by typing this code on your shell.
docker --version
Docker version 25.0.4, build 1a576c5
2.Basic Command Line Knowledge: Familiarity with command-line operations will be beneficial.
Step 1: Pulling the Docker Dind Image
docker pull docker:dind
Step 2: Create a Jenkins bridge Network
docker network create -d bridge jenkins
Step 3: Run the docker dind image
docker run \
--name jenkins-docker \
--rm \
--detach \
--privileged \
--network jenkins \
--network-alias docker \
--env DOCKER_TLS_CERTDIR=/certs \
--volume jenkins-docker-certs:/certs/client \
--volume jenkins-data:/var/jenkins_home \
--publish 2376:2376 \
docker:dind \
--storage-driver overlay2
Step 4: Now you need to Customize the official Jenkins Docker image, by executing the following two steps:
a. Create a Dockerfile with the following content:
FROM jenkins/jenkins:2.452.2-jdk17
USER root
RUN apt-get update && apt-get install -y lsb-release
RUN curl -fsSLo /usr/share/keyrings/docker-archive-keyring.asc \
https://download.docker.com/linux/debian/gpg
RUN echo "deb [arch=$(dpkg --print-architecture) \
signed-by=/usr/share/keyrings/docker-archive-keyring.asc] \
https://download.docker.com/linux/debian \
$(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list
RUN apt-get update && apt-get install -y docker-ce-cli
USER jenkins
RUN jenkins-plugin-cli --plugins "blueocean docker-workflow"
b. Build a new docker image from this Dockerfile, and assign the image a meaningful name, such as "myjenkins-blueocean:2.452.2-1":
docker build -t myjenkins-blueocean:2.452.2-1 .
Step 5: Run your own myjenkins-blueocean:2.452.2-1 image as a container in Docker using the following docker run command:
docker run \
--name jenkins-blueocean \
--restart=on-failure \
--detach \
--network jenkins \
--env DOCKER_HOST=tcp://docker:2376 \
--env DOCKER_CERT_PATH=/certs/client \
--env DOCKER_TLS_VERIFY=1 \
--publish 8080:8080 \
--publish 50000:50000 \
--volume jenkins-data:/var/jenkins_home \
--volume jenkins-docker-certs:/certs/client:ro \
myjenkins-blueocean:2.452.2-1
Step 5: Accessing you jenkins controller.
- Open a web browser.
- Navigate to http://localhost:8080.
Posted on July 1, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
September 7, 2024
July 26, 2024
July 18, 2024