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:

class app {

Map home() {
'name':'bob the builder',


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


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 Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s