After quite a while I finally got some time to install and experiment Docker. My first public experiment would be to dockerize the sample hello world application which can be generated by RESTX when creating a new application.
In a nutshell I wanted to create a restx archive for the hello application and find a simple and generic way to create a Docker image to run this application.
Restx application
Nothing magic here, I just created a new application with restx app new
and asked to create the sample resource. The only hairy part being the creation of the restx archive:
Docker images
Since I want something generic I planned to have two images: one containing only the restx installation and the to run the applications.
Restx
I started from Frédéric Camblor’s image and made a bunch of modifications:
- Upgraded restx to the latest version
- Replaced the base image (
dockerfile/java
, 1 GB) by a leaner one (java
, 600MB) - Created a restx user as I really loath running applications as root
- Exposed port
8080
Which lead to the following Dockerfile
:
This image is uploaded to Docker Hub as ggtoos/restx-docker.
Application
Starting with the restx archive should be straight forward:
restx grab
to unpack the archiverestx deps install
restx app run
The resulting Dockerfile
is:
Using this Dockerfile
you’ll only need to copy your restx archive to /tmp/restx-app.jar
and build your image with docker build
.
Results
First impression: this is blazing fast as it only take 5 seconds to create the container and launch the application. I admit this is not a big application but this is way better than deploying a war on a recent tomcat.
My only issue is that the creation of the application image is really slow as restx needs to fetch the dependencies at this time. This is a waste of time as the dependencies had most probably already been fetched on the developement/build environment. Creating an executable jar at build time would probably be more efficient.