Katrina McIvor | 10 November 2015
Legacy applications can be a problem for companies. Writing new software is all wonderful and easy, you can add whatever libraries you want, use containers to deploy your application easily. But what of the legacy systems. We still need a way to move them into the cloud, or just make deployment a little more predictable. How to use Docker containers for legacy systems was a question that has cropped up a few times as we run the Introduction to Docker and also at other events, such as DevSecCon. They allow for a program to be wrapped up with all its dependencies and then deployed easily in any environment. So what happens when we try and 'dockerise' a COBOL program?
It turned out that it's not actually as bad as it seems. After all, anything that can be expressed as a series of commands can be turned into a Docker container.
Having never written a line of COBOL in my life I went in search of everyone's favourite first program, hello world.
In a new directory, save this file as helloworld.cbl.
COBOL traditionally runs on *nix systems. There's a package in the Ubuntu repositories called open-cobol which will allow us to build and run our program.
So, the Dockerfile for our container looks like this:
Make sure you save this in the same directory as your helloworld.cbl file
So far. So good. Now we want to build the container and run it.
You should, if everything has gone to plan see the message output on the screen:
Networking with something like COBOL? Well a port is a port. Just map your ports from the host system into your container and have whatever needs to talk to your COBOL program connect using them.
The code snippits for this can can be found in git: https://bitbucket.org/kizzie/cobol-docker
That's all well and good you might say, but what if I can't run this using linux? I need to have windows, or FreeBSD, or [insert random operating system here]? Well for windows users - native containers are coming soon. For other linux based operating systems, then we need to start with creating our own base image from scratch. This can also be done for security reasons (if you don't want to trust the official repositories).
Creating a base image uses the scratch base. This tells Docker that the next line used to build the container will be the operating system files.
So, for example, "katbuntu" is defined as:
This is run in a directory where I have all the OS files required for Ubuntu. If I want to change any part of the operating system, I change the files stored in my current directory.
"debootstrap" is a program in debian based systems that provides an easy way to make a copy of a file system. For something like FreeBSD you may need to create an OS from scratch in a virtual machine and then copy all the relevant files and directories directly into your Docker container. Other people have created containers from Solaris and FreeBSD available on the Dockerhub, so have a look at what they have produced!
Now back to figuring out how to save the world...