Visual COBOL includes support for running inside Docker containers. Is there a way a program can determine whether it's running within a container?
HOW TO STEPS:
The built-in routine CBL_GET_OS_INFO, can provide information about the COBOL product in use, and the environment in which it's running. As part of the support for working with containers, this routine has been enhanced to return a new bit flag to indicate whether the program is running in a Docker container.
When the routine is invoked, it returns a parameter block. One of the items returned is described as "Runtime System Capabilities", and a bit within that item indicates if a container is in use.
The attached program is a demonstration of this functionality. It creates a simple report that shows the Product Version, and whether the program is running on a full O/S or within a container.
The program uses the new BIT-OF function in Visual COBOL 6.0 to convert this information into an alphanumeric string for easy interrogation:
determine-docker. * The BIT-OF function is new in Visual COBOL 6.0... move function BIT-OF (cblte-osi-rts-capabilities) to expanded-bits
And then an 88 level COBOL condition is used to test the value:
evaluate true when running-on-docker move "Running in a Docker Container" to docker-status when other move "Running on full O/S" to docker-status end-evaluate
Here's a sample of the report produced by the example program:
Current Product Version: 6 Container Status: Running in a Docker Container
The complete program is attached below.