我希望能够在不同的环境中通过 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"]
Run Code Online (Sandbox Code Playgroud)
我有 appsettings.Production.json 和 appsettings.Development.json 并且我在 program.cs 中配置了我的两个环境,如下所示:
public static IWebHostBuilder CreateWebHostBuilder (string[] args) =>
WebHost.CreateDefaultBuilder (args)
.ConfigureAppConfiguration ((hostingContext, config) => {
config.AddJsonFile …Run Code Online (Sandbox Code Playgroud)