Building Spring Boot cli apps with Docker

The Spring Boot CLI is quite useful when building small groovy scripts.

I recently created a small dockerfile based on Java 8 and ubuntu that makes it easy to use the Spring Boot CLI in Docker.

This is available via the docker hub.

To start, simply add

FROM tomaslin/spring-cli

to your docker file and it will provide you with a docker image with Spring boot CLI, Java 8 and ubuntu to work on your applications.

This post contains a full example on how to use this.

Let’s start by creating a spring boot groovy script:

@RestController
class app {

@RequestMapping("/")
Map home() {
[
'name':'bob the builder',
'address':'poland'
]
}

}

Let’s save this app as app.groovy. I make sure it runs by typing locally:

spring run app.groovy

Now, I can create and save a Dockerfile referencing the spring-cli image:


FROM tomaslin/spring-cli

MAINTAINER tomaslin@gmail.com

ADD app.groovy app.groovy

RUN spring jar app.jar app.groovy

CMD java -jar app.jar

Since the image already contains spring boot cli, I just use the spring jar command to build my jar file.

Now, I can build my application via `docker build -t sampleapp .’

and run it via ‘docker run sampleapp’

I will see my application started.

Leave a comment