[appsettings.json文件在docker run上找不到问题

问题描述 投票:0回答:1

我正在尝试构建和运行.Net Core应用程序的docker映像。

这是我到目前为止所尝试的:

  1. 创建了.Net Core应用程序(.Net Core 2.2)
  2. [使用以下命令发布应用程序

    dotnet publish -c Release
    
  3. 使用以下说明创建了Docker文件:

    FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
    
    COPY myapp/bin/Release/netcoreapp2.2/publish/ app/
    ENTRYPOINT ["dotnet", "app/myapp.dll"]
    
  4. [使用以下命令构建docker映像

    docker build -t planservice -f Dockerfile .
    

[这里,图像已成功构建。但是,当我运行图像时,出现如下错误:

C:\ app> docker run -it --rm planservice

Unhandled Exception: System.IO.FileNotFoundException: The configuration file 'appsettings.json' was not found and is not optional. The physical path i
s '/appsettings.json'.
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean reload)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load()
   at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
   at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
   at myapp.Program.GetConfiguration() in C:\app\MFPServices\myapp\Program.cs:line 64
   at myapp.Program.Main(String[] args) in C:\app\MFPServices\myapp\Program.cs:line 16
c# docker .net-core appsettings
1个回答
0
投票

根据@Jawad的建议,我已经修改了Docker文件以导航到/ app文件夹。appsettings.js应该存在于当前位置才能运行。

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2

COPY myapp/bin/Release/netcoreapp2.2/publish/ app/
WORKDIR /app
COPY . .
ENTRYPOINT ["dotnet", "myapp.dll"]

现在,它可以正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.