2015 01 15
Spring Boot makes it easy to build microservices. Containers are a standard way to run microservices in production.
This post shows how to develop a spring boot application inside of a docker container using the spring-boot-maven-plugin, the Springsource Toolsuite, docker and fig.
The source is a minimal Spring Boot example from this guide to build a RESTful Web Service with spring boot. The full soucecode can be found on github.
Add a dependecy to spring-loaded to the spring boot maven plugin to reload changed classes inside the docker container.
{% highlight xml %}
The Dockerfile: {% highlight text %} FROM dockerfile/java:oracle-java8 MAINTAINER philipp.huegelmeyer@ble.de EXPOSE 8080 ENV http_proxy http://httpproxy.service.ble.de:9090 RUN apt-get update RUN DEBIAN_FRONTEND=noninteractive apt-get install -y —force-yes maven RUN mkdir -p /data/spring-rest WORKDIR /data/spring-rest {% endhighlight %}
The fig.yml:
{% highlight text %} web: build: . #environment:
- MAVEN_OPTS=“-javaagent:springloaded-1.2.1.jar -noverify”
ports: - “8080:8080” volumes: - docker-rest:/data/spring-rest command: mvn spring-boot:run {% endhighlight %}
The container can be build with fig build
and run it with fig up
. Open the maven project inside the springsource toolsuite. Changed classes will be loaded automatically inside the docker container.