COBOL in Docker
| The image | |
| Compile in a container | |
| Mount your source |
The image
The GnuCOBOL project publishes an official image. Pull it once and you have a compiler in a clean room, with nothing installed on your machine:
docker pull olegkunitsyn/gnucobol
Compile in a container
Run the compiler inside the container. Mount the current directory so the compiler sees your source and writes the executable back to it:
docker run --rm -v "$PWD":/src olegkunitsyn/gnucobol
cobc -x -free -o /src/hello /src/hello.cob
Mount your source
Keep your sources on the host and treat the container as a tool, like a compiler version pin. The same trick works in CI: pin the image tag, and every build compiles with the exact same compiler.
Next: COBOL on mainframes
Article author: Arthur Isaev