DevOps training from QA

Docker and legacy applications

Legacy applications can be a problem for companies. We still need a way of moving them to the cloud, or
just making the deployment a little more predictable. This blog focuses on how to do this.


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.

IDENTIFICATION DIVISION

PROGRAM-ID. HELLO-WORLD.

*> hello world program

PROCEDURE DIVISION

    DISPLAY 'Hello world from cobol!".

    STOP RUN

 

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:

from ubuntu:14.04

maintainer Kat McIvor <katrina.mcivor@qa.com>

 

#update and get pre-requisites

run apt-get update

run apt-get install -y open-cobol

run apt-get install -y gcc

 

#copy in the source file

copy helloworld.cbl /helloworld.cbl

 

#compile the code

run cobc -x -free -o helloworld helloworld.cbl

 

#run the compiled program

cmd ["/helloworld"]

 

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.

sudo docker build -t cobol-helloworld .

sudo docker run cobol-helloworld

 

You should, if everything has gone to plan see the message output on the screen:

~/hello-cobol# docker run cobol-helloworld

Hello world from cobol!

 

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:

from scratch

copy . /

 

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.

katbuntu.png

"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...

Docker training from QA

QA offer a one-day Introduction to Docker course as part of our DevOps curriculum.


Katrina McIvor

Katrina McIvor

Principal Technologist | DevOps

Katrina joined QA in the summer of 2014. Before working for QA she was involved in teaching and research, firstly at The University of Birmingham, where she completed her PhD in Computer Science (specialising in agents and AI), and then at Aston University, where she was a lecturer and ran the programming support office. She has around six years' experience teaching individuals, small groups and large lecture audiences. Katrina is a published researcher both nationally and internationally specialising in AI, agents and robotics. Katrina is passionate about all things technical and specialises in teaching Java, Scala, Web Technologies and DevOps within QA.
Talk to our learning experts

Talk to our team of learning experts

Every business has different learning needs. QA has over 30 years of experience in combining the highest quality training with the most comprehensive range of learning services, ensuring the very best fit for your organisation.

Get in touch with our learning experts to talk about how we can help.