1

I am a newby with dockers and want to understand how to deal with environment variables in images/containers and how to configure the CI/CD pipelines. In the first instance I need the big picture before deepdiving in commands etc. I searched a lot on Internet, but in the most of the cases I found the detailed commands how to create, build, publish images.

I have a .net core web application. As all of you know there are appsettings.json files for each environment, like appsettings.development.json or appsettings.production.json.

During the build you can give the environment information so .net can build the application with the specified environment variables like connection strings.

I can define the same steps in de Dockerfile and give the environment as a parameter or define as variables. That part works fine.

My question is, should I have to create seperate images for all of my environments? If no, how can I create 1 image and can use that to create a container and can use it for all of my environments? What is the best practice?

  • 1
    "*My question is, should I have to create seperate images for all of my environments?*" - No, definitively not. The whole idea is to configure the application through environment variables. This is the [3rd factor of a 12factor app (`12factor.net`)](https://12factor.net/config). – Turing85 Dec 14 '21 at 16:01
  • _During the build you can give the environment information_ - What you've described is runtime behavior, not build behavior. – OneCricketeer Dec 14 '21 at 19:06
  • You can dynamically modify the appsettings according to your needs, similar to the approach in this post:https://stackoverflow.com/questions/41349007/set-environment-variable-in-running-docker-contianer – Tupac Dec 20 '21 at 07:24

1 Answers1

0

I hope I am understanding the question correctly. If the environments are the same framework, then no. In each project, import the necessary files for Docker and then update the docker-compose.yml for the project - it will then create an image for that project. Using Docker Desktop (if you prefer over CLI) you can start and stop your containers.

dxLisa3
  • 1
  • 1
  • Hi, thanks for your answer, but can you give me more information? Should i have to create/use a docker-compose.yml file? Or do you have a link to a simple tutorial? – user7383193 Dec 14 '21 at 18:56
  • @user7383193 If you are just running one container, Compose is not needed for deployment – OneCricketeer Dec 14 '21 at 19:06