c# - 如何在docker中设置dotnet core的环境?

标签 c# docker .net-core

我希望能够在不同的环境中通过 docker 运行 dotnet core(现在只是开发和生产),但我的 docker 总是在生产环境中启动。
这是我的 docker 文件:

FROM microsoft/dotnet:sdk AS build-env

WORKDIR /app

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -o out

# Build runtime image
FROM microsoft/dotnet:aspnetcore-runtime
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "test.dll"]

我有 appsettings.Production.json 和 appsettings.Development.json
我在 program.cs 中配置了我的两个环境,如下所示:
 public static IWebHostBuilder CreateWebHostBuilder (string[] args) =>
            WebHost.CreateDefaultBuilder (args)

            .ConfigureAppConfiguration ((hostingContext, config) => {
                config.AddJsonFile ("appsettings.Development.json", optional : false, reloadOnChange : false)
                    .AddJsonFile ("appsettings.Production.json", optional : false, reloadOnChange : false);
            })
            //End of update
            .UseStartup<Startup> ();

我构建了 docker 镜像和容器,但是当它启动时它以生产模式启动我希望它以开发模式启动

最佳答案

ENTRYPOINT ["dotnet", "test.dll", "--environment=Development"]

关于c# - 如何在docker中设置dotnet core的环境?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54901609/

相关文章:

linux - 如何让我的 dotnet 核心应用程序使用不同的包?

asp.net-core - 带有 IIS 的 DotNetCore 2.2 应用程序无法工作 - HTTP 错误 500.0 - ANCM 进程内处理程序加载失败

c# - C# 中的 RSASSA-PSS

c# - 在 CMake 中导入的外部 msproject 无法构建

c# - Parallel.Foreach 问题

docker - NGINX作为另一个容器上的反向代理-如何配置配置文件

c++ - 为什么 QDir::exists() 在 docker 容器中不起作用?

docker - Traefik v2 : 404 while routing HTTP traffic globally to HTTPS

c# - PowerShell 字符串命令中的管道字符在 Csharp C# 代码中无法识别

c# - Polly 记录所有带有 URL、 header 、内容和响应的请求