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..
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.
# Squirrel Dockerfile
# Pull base image
# Install package sources
RUN sed -i 's/# \(.*multiverse$\)/\1/g' /etc/apt/sources.list
# Update everything
RUN apt-get update
# Install java runtime and some tooling
RUN apt-get install -y default-jre
RUN apt-get install -y wget unzip
# Download squirrel
RUN cd /tmp ; wget https://sourceforge.net/projects/squirrel-sql/files/1-stable/squirrelsql-3.8.1-standard.zip
# Unpack squirrel and move it to /usr/local
RUN cd /tmp && unzip squirrelsql-3.8.1-optional.zip -d squirrel
RUN cd /tmp/squirrel && mv squirrelsql-3.8.1-optional /usr/local/squirrel
# Copy some drivers into the image
COPY ./drivers/mysql-connector-java-8.0.12.jar /root/mysql-connector-java-8.0.12.jar
COPY ./drivers/sqljdbc42.jar /root/sqljdbc42.jar
COPY ./drivers/mariadb-java-client-2.3.0.jar /root/mariadb-java-client-2.3.0.jar
# Clean up
RUN rm -rf /var/lib/apt/lists/*
# Define default command.
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:
socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\" &
docker run --rm -e DISPLAY=$hostname:0 squirrel/custom:v1
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).
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.