I'm building a docker image for some code that needs to be compiled using distutils.extension
. I have a Makefile which runs python setup.py build_ext --inplace
.
Should I do
RUN make
or
CMD ["make"]
I found a blog post for maven compile which used RUN
. Also this gcc image suggests using RUN gcc -o myapp main.c
, suggesting that RUN
will work to compile my code, but other resources (How to build a c-image in a container, Should I Compile My Application Inside of a Docker Image) suggest that including compiled code in the image balloons its size, which makes me think I should use CMD
because that won't be executed until the container is run.
RUN comamnds are executed once when the image is building. CMD will execute everytime the container is started.
Using CMD will cause your code to compile every time the container is started. Does your image intends on running the aplication or just creating the aplication, then move it somewhere else? For the former you will definitely want to use RUN to compile it when the image is being built.
Increased image size isn't a concern anymore since the introducion of multi stage builds, as you can compile your application in one image then only transfer the resulting executable to the final image.
It makes no sense to compile in the CMD phrase unless you have a specific reason to do so.