Should I Compile My Application Inside of a Docker

2020-06-16 01:04发布

Although most of the time I am developing Java apps and am simply using Maven so my builds should be reproducible (at least that's what Maven says).

But say you are compiling a C++ program or something a little more involved, should you build inside of docker?
Or ideally use vagrant or another technology to produce reproduce able builds.

How do you manage reproducible build with docker?

2条回答
爱情/是我丢掉的垃圾
2楼-- · 2020-06-16 02:05

You can, but not in your final image, as that would mean a much larger image than necessary: it would include all the compilation tool, instead of limiting to only what you need to execute the resulting binary.

You can see an alternative in "How do I build a Docker image for a Ruby project without build tools?"

  • I use an image to build,
  • I commit the resulting stopped container as a new image (with a volume including the resulting binary)
  • I use an execution image (one which only contain what you need to run), and copy the binary from the other image. I commit again the resulting container.

The final image includes the compiled binary and the execution environment.

查看更多
爷、活的狠高调
3楼-- · 2020-06-16 02:07

I wanted to post an answer to this as well actually because to build on VonC's answer. Actually I just had Redhat Openshift training and they use a tool called Source to Image s2i, which uses docker to create docker images. And actually this strategy is great for managing a private (or public) cloud, where your build may be compiled on different machines, but you need to keep the build environment consistent.

查看更多
登录 后发表回答