In old days (not so old, albeit like a one or two year(s) ago), we used to insert a docker environment variable like IS_DOCKER_CONTAINER using dockerfile in docker images. This was used to determine if an application is running inside a docker container or not. This helped to set certain attributes of the application like logging level and methods, modify certain environmental settings etc and helped controlling behavior of the application. It can also be useful in other situations like to determine whether you want to run selenium tests or not (as selenium web drivers would not be available inside docker container) to run as part of the integration testing.
This is a method we still follow today. Few days back, when we were reviewing the environmental variables inside new dotnet core images based on microsoft/dotnet:2.1-aspnetcore-runtime, we observed one of the built-in settings was as below:
We later checked the dockerfiles and it seemed to be introduced in one of the alpine versions:
Since aspnetcore-runtime is based on alpine images only, it is then carried forward. In a nutshell, this setting can be useful to determine if your .NET core app is running inside container and taking certain decisions. Also, you do not need to insert it using dockerfile anymore. 🙂
Also do note that they also introduce some other useful variables like:
ENV ASPNETCORE_VERSION 2.1.3
which can be useful too.