Struggling with a single dockerfile between environments

My understanding is that one of the big benefits of Docker is to get rid of “works on my machine”. Therefore using the same container in development, staging and production seems to be the general advice.

My issue is that I just can’t see how this works in the real world. I have created all the containers needed for our development environments. The issue is that they contain things that I definitely don’t want in production. They are also built up in different ways to that of a production container.

I think it will be clearer with concrete examples:

  • I am installing the Visual Studio Remote Debugger into my web container. I don’t want this installed in production.
  • I have a SQL Server Container. In development, I want to create a volume to the host machine and attach to pre-existing database files (this is all working fine). This requires me to declare a Volume in my dockerfile. In my CI/Test build, I don’t want to do that. Instead, I want to build up the database on first run. Therefore, I don’t want the Volume mounted. But as this is in the dockerfile, I don’t see how I can exclude it.

It seems much neater to me to create different dockerfiles for each environment (or at least one for dev and one for everything else). But then we wouldn’t be running the same containers in dev as in staging/production. Seems to defeat the point. I do admit that the containers would be much more similar than what we do now, but crucially, not the same.

Am I thinking about this correctly?



why don’t you define a production docker image and then derive your dev docker image from that? the dev container would than just install your Visual Studio Remote Debugger.