Should I Compile My Application Inside of a Docker Image

帅比萌擦擦* 提交于 2019-12-21 04:29:07

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/41688748/should-i-compile-my-application-inside-of-a-docker-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!