To deploy the Jenkins server, we build an image from => Jenkins2.375
Just install inside, the Docker CLI, Docker compose and BlueOcean plugin from Jenkins to show graphical interface for pipelines.
We build the Dockerfile directly from Docker-compose.yml, but you can also build with GitHub actions, Push image on DockerHub and Pull it from the Docker compose file.
You could find this workflow with GitHub Actions in the ".github" folder.
FROM jenkins/jenkins:2.375-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
RUN curl -L "https://github.com/docker/compose/releases/download/`curl -fsSLI -o /dev/null -w %{url_effective} https://github.com/docker/compose/releases/latest | sed 's#.*tag/##g' && echo`/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && \
chmod +x /usr/local/bin/docker-compose && \
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
USER jenkins
RUN jenkins-plugin-cli --plugins blueocean
To run containers just execute the following command :
docker compose up -d
The jenkins service is exposed on port 8080
services:
jenkins:
container_name: jenkins-server
build:
context: .
dockerfile: Dockerfile
ports:
- 8080:8080
- 50000:50000
environment:
- DOCKER_HOST=tcp://docker:2376
- DOCKER_CERT_PATH=/certs/client
- DOCKER_TLS_VERIFY=1
networks:
- local_jenkins
hostname: jenkins
restart: always
volumes:
- jenkins-data:/var/jenkins_home
- jenkins-docker-certs:/certs/client:ro
depends_on:
- docker
Check the containers running :
docker ps
Now to display the Jenkins server on your browser :
http://localhost:8080
For the first start you have to retrieve the initial password generate by Jenkins.
To do that you must connecting on the jenkins-server container and display the password file.
Then enter the password and validate.
docker exec -it jenkins-server /bin/bash
inside the container :
cat /var/jenkins_home/secrets/initialAdminPassword
It' OK, so now create a user and confirm the IP address with the open port.
We are going to create a Jenkins pipeline to Build a simple HTML5 website. You can use my repository or take yours.
https://github.com/Tony-Dja/Docker-contenerized-website
Enter a name for your project
Click on checkbox "Build with parameters", and add 2 variables with string type :
- IMAGE_NAME => name of Docker image you are going to build
- IMAGE_TAG => Tag of the image
From the Build Steps section, select "execute shell script"
And last, add script to clone the repo, and Build image. Then validate project
To run pipeline, click on "Build with parameters" and "Build"
The job is running, you can watch job in progress
The job is finished
In the Dockerfile, we install Blue Ocean plugin. It allows to visualize a graphic interface for our pipeline.
You can find the link in Jenkins navigation menu