All Projects → saturnism → spring-boot-container-demo

saturnism / spring-boot-container-demo

Licence: Apache-2.0 license
No description, website, or topics provided.

Programming Languages

groovy
2714 projects

Spring Boot Docker Example

This is an example Spring Boot "Hello World" micro-service application that can be containerized and subsequently executed in Docker, Kubernetes, and Google App Engine!

This is not an official Google product.

Building

Regular Maven build:

mvn package

Build Docker container:

mvn docker:build

Running

Java

Pretty straight forward:

mvn exec:java

Docker

Without Redis for session:

docker run -ti spring-boot-demo

With Redis for session:

docker run -d --name redis -p 6379:6379 redis
docker run -ti --rm --link redis:redis -p 8080:8080 spring-boot-demo

Docker Compose

Docker Compose uses a descriptor to describe the Docker container and linking configurations. Rather than manually executing commands like the previous section, you can start the demo with Redis by running:

cd src/test/docker-compose
docker-compose up

The configuration is stored in docker-compose.yml

Kubernetes

The following instructions assume that you already have Kubernetes cluster up and running. If not, check out Google Container Engine to get started quickly.

Change directory to where all the Kubernetes configuration files are:

cd src/test/kubernetes

Deploy Redis master pod:

kubectl create -f redis-master-pod.yaml

Create a Redis master service:

kubectl create -f redis-master-service.yaml

Deploy Spring Boot Demo replication controller:

kubectl create -f spring-boot-demo-controller.yaml

Create a service:

kubectl create -f spring-boot-demo-service.yaml

If you are on Google Container Engine, or Kubernetes deployment that supports external services, you can create an external service:

kubectl create -f spring-boot-demo-external-service.yaml

Google App Engine

The instruction assumes that you have Google Cloud SDK already installed and that you are familiar with Google App Engine Managed VMs.

To run locally:

mvn gcloud:run

To deploy into Google App Engine, you'll first need to create a Redis server. You can deploy Redis easily by using Click to Deploy.

Once deployed, update src/main/resources/application-gae.properties file, and set:

spring.redis.host=YOUR_REDIS_MASTER_INSTANCE_NAME

Build the Docker image, so that it generates Dockerfile

mvn docker:build

Finally, deploy the application using gcloud plugin:

mvn gcloud:deploy -Dgcloud.project=YOUR_PROJECT_ID
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].