I’m new to Docker and looking at deploying some C++ programs in containers. These are currently installed on a server and run as cronjobs and perform various maintenance tasks on our systems.
Since the code is in a git repository, I’m guessing this means that building the Docker container will involve installing GCC and git, cloning the git repo, compiling the code then installing it, all inside the container during the build process.
My two questions are - is this the best way to run a C++ program from source in a Docker container, and if so, is there any benefit to uninstalling GCC and deleting the source code after the program has been compiled and installed?
I’m not entirely familiar with how the caching system works, so I’m unclear whether uninstalling the compiler would result in a smaller container, or whether it would mean there are more layers in the container so it would actually make it larger (i.e. downloading the filesystem with the compiler present, then another overlay that sits on top of that and hides the compiler again.)
I’m thinking the alternative is to have a container dedicated to building the program into a (for example) .deb file, then the “real” container can just install the .deb with apt-get/dpkg and not worry about compilers and git.
Which method would be the better option?