gosub

a weblog about computer stuff

Deploying jee webapplication and rdbms with docker

I plan to migrate a testing environment comprised of a few jee webapps running on glassfish and connecting to a firebird database to a set of docker containers. I tried this for one of the application, and here is how it can be done:

What will be deployed

Deployment consists of

Application state in a container

To setup testing and demo environments it will be useful to have a set of known application states versioned and instantly deployable. The docker solution to this seems to be setting up a datacontainer as described here. Since the application i try to deploy here stores its state in the database and in a working directory, we want to fit both in the same container image.

It is recommended to use the same base image for data containers that is used in the other containers which make up your deployment. This will save you some diskspace, but other than that its irrelevant what you use.

The Dockerfile for jacobalberty/firebird:2.5-ss reveals the base image used:

FROM debian:jessie

We want our image to expose two volumes. one for database file(s), and one for the work directory. The Dockerfile below can be used to build this image.

It shall be named appdata, for it stores appdata! to build and run this image execute

docker build -t <your_repo>/appdata .
docker -d --name appdata <your_repo>/appdata

check the result by running docker ps. if all went well you should see output like this:

CONTAINER ID        IMAGE                      COMMAND             CREATED             STATUS              PORTS               NAMES
55c6523c4307        18384fe4a822....e558e295   "/bin/bash"         21 minutes ago      Up 18 minutes                           appdata

which means our datacontainer is up and running.

Databaseserver

getting the image

We will use the firebird 2.5 superserver docker image from jacobalberty/firebird.

docker pull jacobalberty/firebird:2.5-ss

running the container

For a production deployment we would map the exposed database volume to a path in the hosts filesystem (in this case /data/firebird/databases). The image also exposes firebirds default port 3050. We will not expose it on the host machine, but instead build a connection between webapp and database images later.

docker run -d --name firebird -v /data/firebird/databases:/databases jacobalberty/firebird:2.5-ss

But what we want to do is use our datacontainer “appdata” to store the database files. To tell docker about it we have to use the –volumes-from flag when starting the firebird image:

docker run -d --name firebird --volumes-from appdata jacobalberty/firebird:2.5-ss

you can verify that the firebird container uses volumes from appdata by attaching to both containers and writing to the /databases directory. if everything is working as planned, you should see the same content in both containers.

Application and Applicationserver

creating the image

To setup the image for glassfish4 plus webapp, we use a custom shell script and a slightly modified version of the official glassfish Dockerfile from docker hub. both are displayed below.

Lets see whats happening:

The build.sh script

In the Dockerfile