Using Jenkins to build a Docker image

Let's configure a Jenkins job to build a sample microservice application, which was introduced in the previous recipe (my-calc). Perform the following steps to configure and build a Docker image:

  1. On the left navigation, click New Item:
Navigating to create a new item
  1. Put your in desired item name (example: my-calc), select Freestyle project, then click OK:
Creating a new Jenkins Job
  1. In the Source Code Management tab, select Git and set the Repository URL as https://github.com/kubernetes-cookbook/my-calc.git, or you may use your own repository which has a Dockerfile:
Source Code Management settings
  1. On the Build Environment tab, click Add build step to add Build / Publish Docker Image:
Build Environment settings
  1. In the Build / Publish Docker Image panel:
    1. Directory for Dockerfile as current (.)
    2. Choose my-docker in the Cloud that we've set up
    3. Put image as your Docker repository, but append :${BUILD_NUMBER} (example: hidetosaito/my-calc:${BUILD_NUMBER})
    4. Enable Push image
    5. Click Add to add your Docker hub ID credential
    6. Then, click Save:
Docker build/publish settings
  1. Finally, you can click Build Now to trigger a build; for testing purposes you can click five times to see how it works:
Trigger a build
  1. Note that you can see a Console that knows it performs a Docker build and push:
Showing a build log
  1. Access your Docker hub repository; it has been pushed five times (because of clicking on build five times):
Docker hub repository

That's it! You can achieve continuous integration to build a Docker image so that when you update a source in GitHub, you can continuously build and push the latest image to your Docker hub repository by Jenkins.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.146.221.144