Giter VIP home page Giter VIP logo

spring-boot-docker's Introduction

This project contains Dockerfile that creates a base image to run Spring Boot applications.

This is not an official Google product.

How to use this image

Groovy Applications

Create a Dockerfile in your project directory:

FROM saturnism/spring-boot:1.2.3-jdk-8-groovy-2.4.3
ADD . $SRC_DIR

You can then build and run the image:

docker build -t myapp
docker run -ti myapp

You'll notice that everytime the container starts, it will resolve all the dependencies. To avoid this, you can also pre-compile your Groovy application using the onbuild image.

In the Dockerfile, use:

FROM saturnism/spring-boot:1.2.3jdk-8-groovy-2.4.3-onbuild

You can then build and run the image just like the previous method:

docker build -t myapp
docker run -ti myapp

Examples

You can find examples under the Examples directory.

Full Demo with Kubernetes

Videos

Ray used this repository for many of his demos during his talks around the world in conferences. You can find a list of Ray's videos on how to run the demos in his YouTube playlist.

But specifically, checkout the one from Jfokus.

Creating a microservice

  1. Create a new directory, and change into it: mkdir hello-live && cd hello-live

  2. Create Helloworld.groovy

    @RestController
    class Helloworld {
      @RequestMapping("/mul/{x}/{y}")
      def mul(@PathVariable int x, @PathVariable int y) {
        [ x: x, y: y, result: x * y ]
      }
    }
    
  3. Run it: spring run .

  4. Build it: spring jar ~/app.jar .

  5. Run the jar: java -jar ~/app.jar

Containerize the service

  1. Create a Dockerfile
  2. Build the container docker build -t helloworld .
  3. Run it: docker run -ti --rm -p 8080:8080 helloworld

Deploying to Kubernetes on Google Container Engine

This assumes that you have a Google Cloud Platform account, a Container Engine managed Kubernetes cluster, and the associated Project ID.

  1. Tag it: docker tag -f helloworld gcr.io/${PROJECT_ID}/helloworld
  2. Push it to Google Container Registry, a private repository: gcloud docker push gcr.io/${PROJECT_ID}/helloworld
  3. Deploy it in Kubernetes: kubectl run helloworld --image=gcr.io/${RPOJECT_ID}/helloworld -l app=hellworld,visualize=true (the label "visualize" is for demo visualization purposes. You can use whatever labels you like).
  4. Scale it: kubectl scale rc helloworld --replicas=3
  5. Expose it as an external service: kubectl expose rc helloworld --port=8080 --target-port=8080 --type=LoadBalancer

Rolling Update

  1. Make changes to Helloworld.groovy
  2. Build the container as v2: docker build -t helloworld:v2 .
  3. Tag it: docker tag -f helloworld:v2 gcr.io/${PROJECT_ID}/helloworld:v2
  4. Push it: gcloud docker push gcr.io/${PROJECT_ID}/helloworld:v2
  5. Rolling update: kubectl rolling-update frontend --image=gcr.io/${PROJECT_ID}/helloworld:v2 --update-periods=5s

https://spring.io/blog/2015/10/19/springone2gx-2015-replay-spring-boot-micro-services-containers-and-kubernetes-how-to

spring-boot-docker's People

Contributors

saturnism avatar campoy avatar vaquarkhan avatar yufengg avatar

Watchers

 avatar  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.