Demo instructions for Optimizing Spring Boot apps for Docker at Devoxx Belgium 2018
These instructions guide you through building Docker images for Spring Boot applications. Four demos are defined:
- A jar based Docker image
- A classpath based Docker image
- A classpath based Docker image with Eclipse OpenJ9
- Compare the HotSpot and OpenJ9 images
If needed, clone the project:
git clone https://github.com/barecode/spring-petclinic.git
cd spring-petclinic
I usually pre-configure at least 4 terminal windows.: a primary window for demo 1-3 and then three more windows for demo 4. I recommend disabling line-wrapping for the docker stats
window. To do this on mac, run tput rmam
(disables line wrapping). If you need to re-enable line wrapping, run tput smam
.
If demo'ing this at a conference, remember a few things:
- Your text is almost never 'too big'. Your default font size is REALLY SMALL on a projector (even a large one).
- Color contrast is really important. Try to use high-contrast settings. Black on White, or White on Black is safest.
- Bad things happen during demos. Network access is unreliable at conferences. Pre-build everything, take screen shots or build slides which the relevant information!
Branch: git checkout docker-jar
- Build the image
git checkout docker-jar
- Build
./mvnw clean package -DskipTests
- Run
docker run -p 8080:8080 spring-petclinic
- Browse to
http://localhost:8080/
(See Petclinic) - Ctrl-C to stop the Docker container
- Inspect the image size and layers
docker images
docker history spring-petclinic
(note the 38MB layer)
Branch: git checkout docker-classpath
- Build the image
git checkout docker-classpath
- Build
./mvnw clean package -DskipTests
- Run
docker run -p 8080:8080 spring-petclinic
- Browse to
http://localhost:8080/
(See Petclinic) - Ctrl-C to stop the Docker container
- Inspect the image size and layers
docker images
docker history spring-petclinic
(note the 3 layers, the small 1MB layer)
Branch: git checkout docker-classpath-openj9
- Tag the previous image (used in Demo 4)
docker tag spring-petclinic spring-petclinic-hotspot
- Build the image
git checkout docker-classpath-openj9
- Build
./mvnw clean package -DskipTests
- Run
docker run -p 8080:8080 spring-petclinic
- Browse to
http://localhost:8080/
(See Petclinic) - Ctrl-C to stop the Docker container
- Inspect the image size and layers
docker images
docker history spring-petclinic
(note the 3 layers, the small 1MB layer)
- Tag the new image (used in Demo 4)
docker tag spring-petclinic spring-petclinic-openj9
- Open three terminal windows
- In Terminal 1, run
docker stats
- In Terminal 2, run
docker run --name hotspot -p 8080:8080 --rm spring-petclinic-hotspot
- In Terminal 3, run
docker run --name openj9 -p 8081:8080 --rm spring-petclinic-openj9
- In Terminal 1, compare the memory usage of the images