Categories
Continuous Integration Docker Jenkins Uncategorized

Dockerizing Jenkins Pipeline – Simplilearn project

This document is an explanation of the project done for simplilearn-devops-certification. It creates a Docker image using Dockerfile and publishes it to docker hub using Jenkins pipeline. The code can be found on the github.

STEP 1 Set up a VS code workspace and the Github repository.

  • Open VS Code.
  • Create a directory “simplilearn-devops-certification” in the terminal and change directory.
  • Run “git init” to initialize repository.
  • Create a repository “simplilearn-devops-certification “ in the github.com
  • Create a file name “README.md” add details of the project in the file.
  • Execute the steps to do initial commit, This will add the project in the GitHub master branch.
      1. git remote add origin https://github.com/aktechthoughts/simplilearn-devops-certification.git
      2. git add  .
      3. git commit –m “ Initial Commit”
      4. git push –set-upstream origin master

STEP 2 Set up a Jenkin Server and a docker-machine.

“java -jar D:\Softwares\jenkins.war –httpPort=8080”

  • The previous command will run the Jenkin server at localhost:8080 port and it can be accessed in the browser using http://localhost:8080/
  • Select “Install Selected packages” and wait for installation to finish.
  • Create a new user after installation is finished.
  • Install a docker on the same machine where Jenkin is installed

STEP 3  Setup Jenkinsfile in the repository

  1. Create Jenkinsfile in the project root directory.
  2. Add below content in the file.

JENKINS

  • The script has four stages in the Jenkins.
    1. Building Image
    2. Deploying the image in the dockerhub repository
    3. Removing the Image from Jenkin node.
    4. Executing Image from dockerhub.

STEP 4 Register and open https://hub.docker.com/ with your own login.

  • Create a new docker reposiory named ‘simplilearn-devops-certification’
  • Create a file ‘Dockerfile’ in the project created in STEP1
  • Add following conent in the file.

Dockerfile

 

Create a pipeline in jenkins and execute the pipeline to publish the image to the docker hub.