Streaming containerized JAVA applications – Part 1

Introduction

I have the strange habit to try to keep my Macbook as “clean” as possible. That’s why I hate to install all sorts of applications I just want to test or applications that I only use once in a while. I know there are all sorts of methods to prevent cluttering of my harddisk but since I’m a bit of a Docker freak I wanted to find a container solution. In this post I will describe what I did.

In this post I assume you have docker installed on a MacOS device (Macbook, MacBook Pro, etc.) and you have installed XQuartz (xquartz.org). My first application is SQuirreL SQL, an open-source graphical Java application that will allow you to view the structure of a JDBC compliant databases, browse the data in tables, issue SQL commands etc..

The container

To build the image I have used the Ubuntu image as base image. Probably there are smaller base images which also work. The base image is update first and further enriched with a JAVA runtime environment, some tools to unzip the SQuirreL Sql application and the application itself. This results in the Dockerfile below.

As you can see I copy three drivers into the image:

  • the official MySQL JAVA driver (free download from mysql.com)
  • the Microsoft jdbc SQL driver (free download from microsoft.com)
  • the MariaDB driver (free download from mariadb.org)

You can add your own platform drivers to suit your needs.

To build the SQuirreL SQL image simply run the docker build command while you’re in the directory containing the Dockerfile:

$ docker build -t squirrel/custom:v1 .

You will see docker going to work to build the image: the base image is downloaded, updates are performed (and downloaded) and the applications are installed. After some time docker finishes and your image should be ready to test.

Executing the docker images  command should give you a list of images containing the newly build image.

REPOSITORY                TAG          IMAGE ID                CREATED              SIZE squirrel/custom           v1             70cdc9dea37a        1 minute ago        566MB

Running the application

To stream the display output of the running container to the X-system om my Macbook (over tcp/ip) I use the socat utility. Socat is a command line based utility that establishes two bidirectional byte streams and transfers data between them. Because the streams can be constructed from a large set of different types of data sinks and sources, and because lots of address options may be applied to the streams, socat can be used for many different purposes. You can install socat with brew: $ brew install socat . To be able to use brew you first need to install it. You also need some Xcode development tools which can be installed by  $ xcode-select --install . There goes my argument for a clean MacBook….

Nevertheless, to start the container with socat running you have create a small script:

This script first executes socat ensuring there is a byte stream established. Then the script executes docker run wit  an environment variable DISPLAY. In this example I’m also using the –rm option of docker run. This removes the container as soon as it has stopped. This has advantages (direct clean-up, always a new instance) and disadvantages (all your settings in the container will be lost after it stops).

Finally

The result is the SQuirreL SQL application running in a container while the user interface is displayed on your Mac in an X window. My second post about this topic will be showing other applications (tn5250, Scribus) which I have containerized.