I’m sorry, but there are many assumptions in your statements, and they presume one is not following best practices (all of which are WAY beyond the scope of his question).
[quote=“dmaze, post:2, topic:37668”]
I would not recommend trying to add a C compiler to your Docker image, because …the full toolchain is likely to be much larger than your application…you’ll also be distributing your source code with the application.[/quote]
He did not ask this. Yet you chose not to directly answer his question, and instead present this oh so limited perspective. Sorry, where I work (and everyone I know) prefers to setup build chains in a container. Just like you so strongly warn against.
You should Google this topic and understand it, but basically I’ll give you a summary: add the toolchain into a docker container. Then the docker run command MOUNTS (bind mount) a dir on the host OS, say: ~/code-out/. Have you builds put the compiled code THERE, and it’s never IN the container.
This is what thepopular
pbuilder system did, way before Docker was cool: recreate a “clean-room” build environment which is not influenced by the host OS.
Of course, one wouldn’t distribute their build container like you have assumed he would. You just wouldn’t.
He doesn’t specify his desired manner of distribution. Why rail against using containers because he MIGHT distribute a container and MIGHT include unwanted source code in it? The same farfetched scenario exists with tarballs, rpm, and debs.
If you’re assuming he wants to distribute his C code in a minimal container, with nothing else (no code, no build env) then he should have been told to do just that. A runtime container can accept the resulting binary. Yes, that means more than one container, but that’s a VERY common use case. See Docker Compose…
The guys I know who built their dev env ON their host OS, are still stuck on Trusty (Ubuntu 14, 2014) because of that decision. Take a few extra minutes to set your build system up right, and you have something both portable and completely independent of the host OS. Exactly what Docker was made FOR.