Magnolia DevOps series, part 1: a Docker image for Magnolia
To deploy isolated Magnolia instances securely and to connect them together easily can be a challenging task. If you choose the right tool, such as Docker, this issue can be solved in an elegant way.
I recently started writing a Docker base image for Magnolia. This image is still in an early stage of development, and needs a few enhancements such as the ones described at the end of this post. We will see shortly how it can be used to instantiate a new Magnolia instance quickly – but first, let’s have a look at its content.
Image specifications
The image is based on Ubuntu 14.10, JDK 7 and Tomcat 8 and includes JDBC drivers for MySQL and PostgreSQL.
The image does not contain any Magnolia application – a Magnolia WAR file must be generated and copied inside the container to this location: $CATALINA_BASE/webapps.
The container starts automatically an empty Tomcat server and exposes the port 8080.
How to use it
Your Magnolia project must use its own Dockerfile. This file must inherit the Magnolia base image and is responsible for:
Uploading your WAR file into the image.
Modifying the server settings to fit your production needs.
In the following example, we won't use any Magnolia project. Instead, we create a new image which downloads a prepackaged WAR file of Magnolia CE automatically.
First, pull the latest version of the Magnolia base image:
docker pull nicolasbarbe/magnolia-base
In your project directory, create a new Dockerfile:
FROM nicolasbarbe/magnolia-base
MAINTAINER Nicolas Barbé "https://github.com/nicolasbarbe"
ADD http://sourceforge.net/projects/magnolia/files/magnolia/Magnolia%20CE%205.3.6/magnolia-bundled-webapp-5.3.6.war/download?use_mirror=autoselect $CATALINA_BASE/webapps/ROOT.war
Build the container and give it a name:
docker build -t one-author-derby .
And start an instance:
docker run -p 3000:8080 one-author-derby
A new instance of the container one-author-derby is created with a Magnolia instance that can be accessed through its URL: http://localhost:3000
Note : If you are using MacOS, you must use the IP of the boot2docker virtual machine (boot2docker ip) instead of localhost.
As you can see, deploying a new Magnolia instance with Docker is simple.
However, this setup has some limitations – How to keep the data when the container is restarted? How to integrate my Docker images in my build process? How to deploy multiple type of Magnolia instances? I will answer those questions in another post soon! Stay tuned!
The source code of the example is available here.