Multiple Dockerfiles for Build and Deploy?

Hello. We have multiple services, some of them written in go, some in java. Some of them run on Alpine, another on Ubuntu.
The question is should we use separate Dockerfiles for build and for “run”?
In details: For now we have two docker-compose files, one for build-and-push-to-registry and another is to pull images from registry and deploy on staging/production.
The main idea is that we have separate docker-compose-run.yml and docker-compose-build.yml, also separate Dockerfiles for each container: Dockerfile-build which actually build binaries from sources inside of container and Dockerfile-run which just use image from registry and execute CMD.

Is this correct or I missed something? Thanks

just an an idea.
You could go with a Dockerfile, where you download the compiler, compile your app and then uninstall the compiler. This way you do not need to separate Dockerfiles for run and build.

Uninstalling the compiler should/could be done by:

  • do the install, compile, uninstall in the same RUN statement
  • or by docker build --squash, which is supported by docker 17.03