I have 3 configs in service:
1 - appsettings.development.json
2 - appsettings.testing.json
3 - appsettings.production.json
And i have 3 launch settings for them as well in launchsettings.json
:
{
"profiles": {
"DevelopmentDockerProfile" {
"commandName": "Docker",
"environmentVariables": {
"DOTNET_ENVIRONMENT": "development"
}
},
"ProductionDockerProfile" {
"commandName": "Docker",
"environmentVariables": {
"DOTNET_ENVIRONMENT": "production"
}
},
"TestingDockerProfile" {
"commandName": "Docker",
"environmentVariables": {
"DOTNET_ENVIRONMENT": "testing"
}
}
}
}
And i can normally run service, using correct configuration only on local machine.
I can not push DOTNET_ENVIRONMENT
variable with service when publishing.
Is there any way to bind environment variable to publishProfile.pubxml
or whatever else, that environment variable DOTNET_ENVIRONMENT
will magically appear in docker service on host machine?
CodePudding user response:
Short answer
No, there is no such option.
Longer one
First of all, you can easily set environment variables using Environment.SetEnvironmentVariable("name", "value")
. But that's probably not what you want.
What you might want is to configure environment variables in configs for container/orchestration tool you use, either set in docker command line (docker run -e VARIABLE_NAME=value
) or in docker-compose.yml
for Docker Compose or in service YAML config for k8s.