The most common way to build an application container image using Docker is to use a Dockerfile. Dockerfile is an imperative language describing the operations required to produce the resulting image. Some of the operations create new filesystem layers; others operate on metadata.
We will not go into details and specifics related to Dockerfiles. Instead, we will show different approaches to containerizing a C++ application. For this, we need to introduce some syntax and concepts related to Dockerfiles.
Here is an example of a very simple Dockerfile:
FROM ubuntu:bionic
RUN apt-get update && apt-get -y install build-essentials gcc
CMD /usr/bin/gcc
Typically, we can divide a Dockerfile into three parts:
- Importing the base image (the FROM instruction)
- Performing operations within the container that will result in a container image (the RUN instruction)
- Metadata used during runtime (the CMD command)
The latter two parts may well be interleaved...