Sunday, April 16, 2017
This section provides the steps needed to run the Spring Boot micro service as a Docker container inside Kubernetes.

  • Copy the MyFirstApp-0.0.1-SNAPSHOT.jar built in the previous section to another folder say C:\MyFirstApp.
  • Let us now create a Docker container using this standalone jar. We need to introduce the Docker file. Create a file with name Dockerfile in C:\MyFirstApp and add the following lines. 
FROM java:8
ADD MyFirstApp-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

  • Dockerfile and the MyFirstApp-0.0.1-SNAPSHOT.jar should be under the same folder.
Create Dockerfile
  • Understanding the elements of a basic Dockerfile.
  1. FROM specifies the base image on which container is built. In this case we use java:8 which uses Java container as both the build and runtime environment.
  2. ADD element copies the standalone Jar to app.jar.
  3. ENTRYPOINT specifies a command that will be executed when the container starts. In this case “java –jar app.jar”.
    Note from Kubernetes:
    When using a single VM of Kubernetes, it’s really handy to reuse the minikube’s built-in Docker daemon; as this means you don’t have to build a docker registry on your host machine and push the image into it - you can just build inside the same docker daemon as minikube which speeds up local experiments. Just make sure you tag your Docker image with something other than ‘latest’ and use that tag while you pull the image. Otherwise, if you do not specify version of your image, it will be assumed as :latest, with pull image policy of Always correspondingly, which may eventually result in ErrImagePull as you may not have any versions of your Docker image out there in the default docker registry (usually DockerHub) yet.

    • To start Kubernetes cluster use “minikube start”. This should start a local Kubernetes cluster on your laptop. You can see a minikube VM entry added in Oracle VM Virtual Box Manager.
    Oracle VM Virtual Box - minikube instance

    • Once you start minikube the console would look like this. Now we are ready to deploy applications on kubernetes.
    minikube start
    • Get the minikube IP using the command "minikube ip". We will run the containerized app on this IP.
    minikube IP 
    •  Run “minikube docker-env” to get the environment of built-in docker daemon.
    minikube docker-env
    • Run the last command displayed above to configure the shell for the docker environment.
    Set the docker environment
    • Verify by running “docker ps” command. You should see several kubernetes related containers already running.
    docker ps listing
    • Go to the folder where we copied the Spring Boot standalone Jar. We already have the Dockerfile here. Run the command "docker build –t myfirstapp:v1 ." to build the docker image. It is important to specify the version tag when working with Kubernetes environment. This command should pull the java libraries, add the Spring Boot application, set the entry point and build the container for us.

    Build docker image
    • Verify if the container is listed by running the "docker images" command. We will see an entry for the myfirstapp container.
    docker images listing
    • Now it is time to start our container in kubernetes. We will leverage kubectl to run this container.
    kubectl run myfirstapp –image=myfirstapp:v1 –port=8080

    kubectl run

    • Launch the minikube dashboard and verify if the application is created. Run the command “minikube dashboard” this should launch a browser and display the dashboard. You can see the app running in dashboard.
    minikube dashboard launch
    Kubernetes dashboard
    • Some useful commands. Use “kubectl get pods” to get the list of pods in the cluster. Use “kubectl get services” to get list of services running in the cluster.
    kubectl get pods
    kubectl get services
    • Next step is to expose this application for external access as a service.  Use the command “kubectl expose deployment myfirstapp –type=NodePort”.
    kubectl expose service

    • Run the “kubectl get services” command again to see if myfirstapp is listed.
    kuebctl get services listing exposed service
    • Verify if the application works. Using the browser. Type the URL to invoke the API.  (or) Run the command “minkube service myfirstapp”. This should automatically launch the browser. Append the URL sayhello to get the message.
    minikube service myfirstapp
    Launch myfirstapp API from kubernetes IP

    Now we have successfully deployed and run a Spring Boot application as a container on Kubernetes.


    1. This comment has been removed by the author.

    2. This comment has been removed by the author.

    3. This comment has been removed by the author.

    4. This comment has been removed by the author.

    5. I just see the post i am so happy the post of information's.So I have really enjoyed and reading your blogs for these posts.Any way I’ll be subscribing to your feed and I hope you post again soon.
      Analytics Training In Chennai

    6. Interesting article! Thank you for sharing : usefull site

    7. This comment has been removed by a blog administrator.

    8. This comment has been removed by a blog administrator.

    9. This comment has been removed by a blog administrator.

    10. Get yourself enrolled in devops online training program as early as possible and begin your journey to an exciting online academic venture. Get 175$ devops complete course at only 10$ [limited time discount]
      Discount link:
      Coupon Code: MAXIMUS10

    11. This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.Really it was an awesome article...very interesting to read..please sharing like this information.
      Hadoop Training in Chennai
      Big Data Training in Chennai
      Python Training in Chennai
      Python Training Centers in Chennai
      Data Science Training in Chennai
      Data Science Course in Chennai
      Data Analytics Training in Chennai
      Best AngularJS Training in Chennai
      AngularJS Training in Chennai
      QlikView Training in Chennai
      Informatica Training in Chennai

    12. Hello, this is fastidious post I actually loved reading this.
      Tony M.

    13. For over 15 years, EA Sports has released annual iterations of its most popular sports series, FIFA.
      Now after the grand success of Fifa 18 which got released in September 2017, hype has already started building for the next installment, the Fifa 19.
      To know further details about the next installment, take a look FIFA 19 release date

    14. I think this is an informative post and it is very useful and knowledgeable. I really enjoyed reading this post gmail login

    15. Needed to compose one little word yet thanks for the suggestions that you are contributed here...
      Best Online Software Training Institute | Spring Boot Training


    Contact Form


    Email *

    Message *

    Back to Top