https://github.com/arnab-developer/dockerenvvariable
Docker environemnt variable
https://github.com/arnab-developer/dockerenvvariable
Last synced: 5 months ago
JSON representation
Docker environemnt variable
- Host: GitHub
- URL: https://github.com/arnab-developer/dockerenvvariable
- Owner: Arnab-Developer
- License: mit
- Created: 2021-04-09T18:47:41.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-11-01T15:19:09.000Z (over 4 years ago)
- Last Synced: 2025-06-11T05:42:42.709Z (about 1 year ago)
- Language: HTML
- Size: 648 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Docker environemnt variable
This is a demo app to show how we can set `ASPNETCORE_ENVIRONMENT` in the
docker container at the time of docker container start.
This sample app is having two different connection strings in `appsettings.json`
and `appsettings.Development.json`.
```
"ConnectionStrings": {
"ConStr": "prd con str"
}
```
```
"ConnectionStrings": {
"ConStr": "dev con str"
}
```
When you request the `Home > Index` method then the application logs the value of
the connection string.
```c#
string conStr = _configuration.GetConnectionString("ConStr");
_logger.LogInformation(conStr);
```
When we run this app from Visual Studio then we can provide the `ASPNETCORE_ENVIRONMENT`
value in `launchSettings.json` and based on that you can see the output in the log.
```
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
```
But when we publish the app and store it in a docker image and run a container
from that image then we can't use `launchSettings.json`. In that case we can
provide the value of `ASPNETCORE_ENVIRONMENT` at the time of docker container run.
To create a docker image
```
docker build -t dockerenvvariable:1.0.0 .
```
To run a container from the image with `ASPNETCORE_ENVIRONMENT` value
```
docker run --name dockerenvvariable-c1 -p 80:80 -e ASPNETCORE_ENVIRONMENT=Development dockerenvvariable:1.0.0
```
Request `http:\\localhost:80` from a browser and you can see the value `dev con str` in the
log file.
## Tech stack
Visual Studio 2019, ASP.NET 5 and docker desktop.