英文:
using visual studio DockerfileRunArguments parameter within launchsettings.json
问题
I am creating container app than uses a Docker container.
> ASPNETCORE_ENVIRONMENT="Staging"
我正在创建一个容器应用程序,它使用一个Docker容器。
ASPNETCORE_ENVIRONMENT="Staging"
I figured I could reference this docker environment file with --env-file dockerfile-staging.conf
我想我可以使用 --env-file dockerfile-staging.conf 来引用这个Docker环境文件。
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
"DockerfileRunArguments": "--env-file dockerfile-staging.conf",
"publishAllPorts": true,
"useSSL": true
}
The environment variable ASPNETCORE_ENVIRONMENT is not set and by default is Development.
环境变量 ASPNETCORE_ENVIRONMENT 未设置,默认为 Development。
I do not see any errors.
我没有看到任何错误。
If I use the following the aspnetcore environment variable is set as Staging correctly.
如果我使用以下内容,则 aspnetcore 环境变量将正确设置为 Staging。
"DockerfileRunArguments": "-e ASPNETCORE_ENVIRONMENT=Staging"
英文:
I am creating container app than uses a Docker container.
> ASPNETCORE_ENVIRONMENT="Staging"
I figured I could reference this docker environment file with --env-file dockerfile-staging.conf
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
"DockerfileRunArguments": "--env-file dockerfile-staging.conf",
"publishAllPorts": true,
"useSSL": true
}
The environment variable ASPNETCORE_ENVIRONMENT is not set and by default is Development.
I do not see any errors.
If I use the following the aspnetcore environment variable is set as Staging correctly.
Any Idea why may be wrong?
"DockerfileRunArguments": "-e ASPNETCORE_ENVIRONMENT=Staging",
答案1
得分: 1
--env-file dockerfile-staging.conf
没有生效,因为 VS 在 docker run
中传递了 -e ASPNETCORE_ENVIRONMENT=Development
,而 Docker 优先使用命令行中的值。使用 -e
的原因是相同的。
作为替代方案,您可以使用以下方式:
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
"publishAllPorts": true,
"useSSL": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Staging"
}
}
environmentVariables
中的值仅适用于该进程,因此即使在容器工具窗口中看不到该值,您也会在您的进程中看到它。
英文:
--env-file dockerfile-staging.conf
isn't working b/c VS is passing -e ASPNETCORE_ENVIRONMENT=Development
as part of the docker run
and docker prioritizes the value from the command line over that in the env file. Using -e is working for the same reason.
As an alternative you can use:
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
"publishAllPorts": true,
"useSSL": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Staging"
}
}
The values in environmentVariables
are set for just the process, so even if you don't see the value in the container tools window, you will see it in your process.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论