Simple local install a Jenkins instance using Docker (MacOS version)
I want to show you how to install a Docker using Dockerfile, and then simply run a Jenkins instance locally.
In case you don’t have Homebrew installed yet, you only need to open a terminal and execute the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Now that you have Homebrew installed, you can execute the following command to install Docker:
brew cask install docker
How can you validate that the installation finished successfully from the command line? Execute docker --version
.
Create a bridge network in Docker using the following docker network create.
docker network create jenkins
To execute Docker commands within Jenkins nodes, start by downloading and running the docker:dind
Docker image using the following docker run
command.
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
Set up a Dockerfile in your project directory with the following content:
FROM jenkins/jenkins:2.462.1-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"
Create a new Docker image from this Dockerfile and give it a meaningful name, like jenkins-latest
docker build -t jenkins-latest .
Start a container using your jenkins-latest
image in Docker with the following docker run
command.
docker run \
--name jenkins-latest \
--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 \
jenkins-latest
Launch your web browser and navigate to localhost:8080
to access the Jenkins application. Wait for the Unlock Jenkins page to load.
As shown in the image above, the Jenkins container is locked. We’ll need the administrator password to unlock Jenkins. Run the following command to retrieve the initial administrator password needed to unlock Jenkins:
#This command will print the password at the console.
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Or from the Jenkins console log output, copy the automatically-generated alphanumeric password using commanddocker logs jenkins-latest
.
Next, select Install Suggested Plugins to allow the installation of the necessary plugins
Create an Admin user and password. Then validate the Jenkins URL and Save and Continue.
Well done!!!🥳😎