Installing Jenkins Using Docker on Windows

(Last Updated On: )

This post is how to install Jenkins using Docker in Windows.

Install Docker

Go to Docker and download “Docker Desktop for Windows – x86_64”. Then run as administrator and install. If you don’t have an account you can create one.

Then open Docker Desktop and go to settings and enable the following “Enable Docker terminal”.

Once you are done you need to start the Docker Engine.

 

 

 

If you get the following error “Failed to initialize: unable to resolve docker endpoint: open C:\Users\<USER>\.docker\machine\machines\default\ca.pem: The system cannot find the path specified.” Then go to environment variables and modify DOCKER_CERT_PATH and set to “C:\Users\<USER>\.docker\machine\certs”.

Then open the docker terminal.

Install Jenkins

Create a network called “jenkins”. This will give you back the id.

  1. docker network create jenkins

You can check that it created successfully by running the following command

  1. docker network ls

Next we run a docker:dind Docker image. If you don’t have the docker image it will download it.

A dind is a Docker In Docker allows developers to run a Docker container within an already running Docker container to support CI/CD pipelines and create sandboxed container environments.

  1. 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

Next we create a Dockerfile

  1. FROM jenkins/jenkins:2.462.2-jdk17
  2. USER root
  3. RUN apt-get update && apt-get install -y lsb-release
  4. RUN curl -fsSLo /usr/share/keyrings/docker-archive-keyring.asc \
  5. https://download.docker.com/linux/debian/gpg
  6. RUN echo "deb [arch=$(dpkg --print-architecture) \
  7. signed-by=/usr/share/keyrings/docker-archive-keyring.asc] \
  8. https://download.docker.com/linux/debian \
  9. $(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list
  10. RUN apt-get update && apt-get install -y docker-ce-cli
  11. USER jenkins
  12. RUN jenkins-plugin-cli --plugins "blueocean docker-workflow"

Next we will build a new docker image with the Dockerfile from the previous step. Be sure to name it appropriately and include versions. If you don’t have the right image it will get it for you. Make sure you are in the directory where you saved your Dockerfile.

  1. docker build -t jenkins-blueocean:2.462.2-1 .

Next we run the image as a container in Docker

  1. 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 --volume jenkins-data:/var/jenkins_home --volume jenkins-docker-certs:/certs/client:ro --publish 8080:8080 --publish 50000:50000 jenkins-blueocean:2.462.2-1

Docker Container Logs using the below command. This will show you the password.

  1. docker logs jenkins-blueocean

Record the password located “/var/jenkins_home/secrets/initialAdminPassword”.

  1. docker exec jenkins-blueocean cat /var/jenkins_home/secrets/initialAdminPassword
  2.  
  3. or
  4.  
  5. docker exec jenkins-blueocean bash
  6. cat /var/jenkins_home/secrets/initialAdminPassword
  7. exit

Then navigate to http://localhost:8080 and enter the password in the “Unlock Jenkins” screen.

 

 

 

 

 

Then select the packages you want to install and click install.

Once the packages install then you need to create the admin user.

Then select your url and click “Save and Finish”.