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.
- git remote add origin https://github.com/aktechthoughts/simplilearn-devops-certification.git
- git add .
- git commit –m “ Initial Commit”
- git push –set-upstream origin master
STEP 2 Set up a Jenkin Server and a docker-machine.
- Download Jenkin.war from http://mirrors.jenkins.io/war-stable/latest/jenkins.war
- Execute this on a terminal of the machine using
“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
- Create Jenkinsfile in the project root directory.
- Add below content in the file.
- The script has four stages in the Jenkins.
- Building Image
- Deploying the image in the dockerhub repository
- Removing the Image from Jenkin node.
- 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.
Create a pipeline in jenkins and execute the pipeline to publish the image to the docker hub.