Here's a lightweight way to build and run C / C ++ programs in a Docker container. There is a lot of information about Go, Python, Java, etc. as a met

How to create a lightweight Docker execution environment for C / C ++

submited by
Style Pass
2021-05-17 11:32:17

Here's a lightweight way to build and run C / C ++ programs in a Docker container. There is a lot of information about Go, Python, Java, etc. as a method of building a Docker execution environment, but I will share it because there was no article on how to build a good Docker environment for C / C ++.

Recently, Docker has a function called multi stage build, which creates a Docker image in two stages. Mainly, in the Dockerfile, create a build environment for creating an executable file in the first stage, and in the second stage, save a lightweight runtime environment just for executing the created executable file as the final Docker image. Is becoming mainstream. Apply these to C / C ++ programs as well.

Recently, Google has released a lightweight and secure Docker image called a distoless image, which is specialized for execution and has limited functions. For details, there are people who explain in detail here. I would like to use this environment, but C / C ++ may use a dynamically linked library that links the library at runtime, in which case the program cannot be executed in the distoless environment where it is difficult to add additional packages. .. Therefore, we will use Alpine Linux, a distribution that is said to be lightweight and has basic functions such as adding packages. You can read more about Alpine Linux here.

Leave a Comment
Related Posts