Tech bytes# Running Jenkins in a Docker Container

Tech bytes# Running Jenkins in a Docker Container

Would you like to use Jenkins in your machine and don't want to follow the traditional installation process ? If your say YES - then follow along this brief article !

Prerequisites:

This article assumes you have some idea of what docker is and how to use it. The pre-requisites to get started are:

  • Docker running in your machine

If you are completely new to docker, I would highly recommend starting from here.

Installation Steps:

  • Create a folder called build and add a Dockerfile in it with content as below.
# build/Dockerfile
FROM jenkins/jenkins:lts-alpine

USER root 
RUN apk add docker
  • Create a docker-compose.yml as below:
#docker-compose.yml

version: "3.8"

services:
  jenkins:
    build: build/
    ports: 
      - 8090:8080
    volumes:
      - "jenkins.data:/var/jenkins_home"
      - "/var/run/docker.sock:/var/run/docker.sock"

volumes:
  jenkins.data:
  • Run the below command to start the service:
docker-compose up -d
  • Open the browser at:
localhost:8090
  • We get a jenkins screens as below for the initial administrator password

image.png

  • Get the password from:
docker-compose exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword
  • After entering the password from above step, Jenkins shows the plugin selection screen.

Jenkins Plugin Screen

After the successful installation of the required plugins you will be redirected to Jenkins Dashboard page. You may create an admin user if required.

Jenkins Dashboard

That's it. You can use Jenkins now to create and run jobs as long as the container is running :)

Did you find this article valuable?

Support Rakesh Vardan by becoming a sponsor. Any amount is appreciated!