我希望能够在不同的环境中通过 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/