Dockerfile strategy

Quick question:

Let’s say we’ve got 100s of microservices (.NET in this case) that we’re wanting to build docker images for. Would you prefer:

  1. A Dockerfile alongside each microservice’s source code specific to that code
  2. A single Dockerfile with build arguments that allow you to specify the the project to be built to avoid 100s of Dockerfiles which are similar
    In this case, the microservices are generated from a template, so their code/directory structure is identical.

If they all have a similar Dockerfile, just go with a single Dockerfile.

There is a better alternative…

Create a base Dockerfile, publish the image

By default, each microservice can use the base image

However, if there is something unique to an image, set up a new Dockerfile with the single image as the FROM

I’ve seen this pattern work really well in polyglot shops where you have a base image for each language/framework

If they are generated, there is no objection to just also generate the Dockerfile with it…

Depending on the level of customization you need you might also consider buildpacks