[英]How to push the correct configuration data with C# worker service to swarm/kubernetes?
I have 3 configs in service:我在服务中有 3 个配置:
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
:我在
launchsettings.json
中也有 3 个启动设置:
{
"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.发布时,我无法使用服务推送
DOTNET_ENVIRONMENT
变量。
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?有没有办法将环境变量绑定到
publishProfile.pubxml
或其他任何东西,该环境变量DOTNET_ENVIRONMENT
会神奇地出现在主机上的 docker 服务中?
No, there is no such option.不,没有这样的选择。
First of all, you can easily set environment variables using Environment.SetEnvironmentVariable("name", "value")
.首先,您可以使用
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. 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.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.