I followed these instructions for Ubuntu 12.04.
In addition to that I also added my user to the 'docker' group.
sudo usermod -a -G docker $USER
This allows the user to run docker without having to type 'sudo' each time.
For the rest of the steps I mostly followed as described here with some minor variations because I was using the 'New Spring Starter' wizard in STS which does some of the pom setup for us.
In STS use the 'New Spring Starter' wizard to create a new web app (select the 'web' starter dependency in the wizard).
I called my app 'spring-boot-docker' and also changed the 'artifact-id' to 'spring-boot-docker'.
You can add some stuff to your app if you want (a hello world page). I was content with what boot generated... which is an webserver that only serves up 404 error pages.
Create a 'docker' folder at the root of your project.
Create a file 'docker/Dockerfile' and put this content in it:
FROM dockerfile/java:oracle-java7
ADD spring-boot-docker-0.0.1-SNAPSHOT.jar /opt/spring-boot-docker/
EXPOSE 8080
WORKDIR /opt/spring-boot-docker/
CMD ["java", "-jar", "spring-boot-maven-docker.jar"]
Add this to the pom:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/</outputDirectory>
<resources>
<resource>
<directory>docker</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
First we need to build our stuff with maven. From the root of the project:
mvn clean install
Then we can build the image
cd target
docker build -t spring-boot-docker .
Check that the image was create and determine its id:
docker images
This shows you a list of images find the 'spring-boot-docker' one and write down its ID to use in the next command:
docker run -p 8080:8080 9969adf59c45
You can now connect to http://localhost:8080/
Note: unless you actually added something to your app (like a hello world page) you'll get a 404 error page.