Continuous Deployment for Docker Image, Build and push Docker image to Docker hub using Jenkins Pipeline from Windows System
Jenkins Pipeline:
Jenkins Pipeline uses a build pipeline plugin which supports Continuous delivery pipeline into Jenkins. A continuous delivery (CD) pipeline is an automated expression of your process for getting software from version control right through to your users and customers. The definition of a Jenkins Pipeline is written into a text file (called a Jenkinsfile) which in turn can be committed to a project’s source control repository.
Prerequisites: 1- Windows machine installed following software.
2- Installed Docker on Windows.
3- Installed Jenkins
4- Docker Hub Account
Step 1- Install Docker on Windows: I'm using Windows 7 for the demonstration, You can follow this blog to finish the Docker for Windows installation.
https://linuxhowtoguide.blogspot.com/2019/02/how-to-install-docker-in-windows-7.html
Step 2- Install Jenkins On Windows: Follow this blog to finish the Jenkins installation on Windows: How to Install Jenkins on Windows Machine.
https://linuxhowtoguide.blogspot.com/2018/07/how-to-install-jenkins-on-windows.html
Step 3- Complete pre-requisites: To add docker hub login details open Jenkins and go to add credentials page: On add credentials page add docker User and Password
After adding credentials. In the Jenkinsfile, I have defined steps to stop and delete existing container so we need to run following command before continuing. Open Docker quick terminal and the command.
$ docker run -dit --name apache2 -p 80:80 ubuntu
The above command will create a container of ubuntu with name apache2. Let's continue.
Step 4- Setup Jenkins Job:
Open Jenkins > new project >Enter Project name > Choose Project type Pipeline
Choose Ok > Choose this project is parameterized > fill out the details as in the picture below
On the Pipeline section select Definition pipeline Script from SCM > Select type Git > Enter Git repository URL > click on Save
In my case I'm using public git repository, if you have private repository define you login details in the pipeline section. Jenkins Job is ready to build.
Step 5- Build and test Jenkins job:
choose to Build with parameters select your docker user and click on the build button.
After successfully complete, you will see output like this.
Login and Check pushed image in your Docker Hub account.
Build and push has completed successfully to Docker Hub. Based on this you build other customs Docker Image and push to your Docker hub account.