Giter VIP home page Giter VIP logo

ci-cd-using-jenkins-for-build-the-image-and-upload-on-dockerhub-and-pull-the-image-and-run-container's Introduction

As we have build the jenkin server and reactjs server in previous doc and build image from docker for reactjs app in application server. Now we have to build image from jenkin only and push the image in docker with below steps and pull the image from dockerhub run the container with jenkin only.

Step-1: First create the New Item in jenkins with the name and choose pipeline.

image

Step-2: Give the same configuration as like previous but now we need to mention the repository URL for github which is for docker build image

https://github.com/mayankkh1/docker.git

Step-3: Put the jenkins file which is present in current repository in your code.

Step-4: Put the docker and nginx file which is present in current repository in your code.

Step-5: After that create webhook URL in github with below url:

http://JenkinServerIP:8080/github-webhook/

Step-6: Now install plugin in Jenkin related to docker:

CloudBees Docker Build and Publish plugin Docker Pipeline Docker plugin docker-build-step

Step-7: Enter the credential for dockerhub authentication in managecredentials as like ubuntu user.

Manage Jenkins ==> Manage Credentials ==> jenkins ==> Global credentials (unrestricted) ==> Add Credentials ==> Put the details and create

Step-8: Now add the ubuntu user or SSH user which is used for ssh authentication in docker group with below command for running the docker commands:

usermod -aG docker ubuntu

Step-9: Now try to run the build manually first if it's working fine then try with CI from webhook after changes the file in github

Step-10: Afer that we need to add more stage in jenkin file for continuous deployment of build image in manage node and run the container with that.

 stage('Deploy to Server') {
  steps{
    
    sh "docker pull $imagename:$BUILD_NUMBER"
    sh "docker container rm -f mywebappserver"
    sh "docker container run -d -p 8080:80 --name mywebappserver $imagename:$BUILD_NUMBER"

       
  }
}

Step-11: Now we have to enable the caching in nginx as like below:

http {
   # ...
   /data/nginx/cache keys_zone=mycache:10m loader_threshold=300 loader_files=200;
   server {
       proxy_cache mycache;
       location / {
           proxy_pass http://localhost:8000;
       }
      }
   }

ci-cd-using-jenkins-for-build-the-image-and-upload-on-dockerhub-and-pull-the-image-and-run-container's People

Contributors

mayankkh1 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.