General
I started experimenting with building containers using Gradle as part of a development cycle with minimum duration feedback cycle and maximum portability for Microservices. I’ll write a bit more about that later, but thought that documenting this process of creating and publishing a container would be useful.
At the same time I wanted to combine Spring Boot and Scala, so this also acts as an example for that.
TL;DR
The example can be run in local VirtualBox Docker environment with:
| |
And just as easily the container could be located in Amazon Web Services or Google Compute Engine or Azure.
Prerequisites
In this example I’m using OS X but all of the components should be as easily installable and runnable on Windows. I use brew to install the packages, but you can also install all of the mentioned tools by following the instructions on their homepage.
Docker Machine
Using Docker Machine provided environment for building the containers makes things very simple. With Docker Machine you can use both a local development environment and cloud based solutions as easily. In this article I will use the VirtualBox based local environment for building the container and running the example.
VirtualBox
The local Docker Machine environment uses VirtualBox to host the boot2docker instance.
Docker client
Gradle-docker plugin uses the docker client to communicate with the Docker Machine instance.
Installing the prerequisites
| |
Creating the local Docker Machine environment
Creating the instance
| |
Pointing local Docker client to dev instance
| |
Finding out the IP of the created dev instance
The IP of the created instance can be checked with
| |
or with docker-machine ip dev.
Checking out the project
The repository can be checked out with
| |
Running the example locally
| |
Testing the example
Now you should be able to point the browser to http://localhost:8080/hello.
Building the container
Container is built by running
| |
This uses the local docker client which has been configured to use the Docker Machine environment for building the container. The first time build will take some time as the base image containing the JRE is downloaded from the docker.io.
After the build is finished, the created image can be checked with
| |
Running the container
Container can be run with
| |
Testing the container
The application should be available in the address that you can query with
docker-machine ip. For example http://192.168.99.100
and in the port 80 that was exposed when running the container.