我正在尝试构建和运行 .Net Core 应用程序的 docker 镜像。
到目前为止,这是我尝试过的:
- 创建了一个 .Net Core 应用程序(.Net Core 2.2)
使用以下命令发布应用
dotnet publish -c Release
使用以下说明创建了一个 Docker 文件:
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 COPY myapp/bin/Release/netcoreapp2.2/publish/ app/ ENTRYPOINT ["dotnet", "app/myapp.dll"]
使用以下命令构建 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
最佳答案
根据@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"]
现在,它工作正常。
关于c# - 在 docker run 上找不到 appsettings.json 文件问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59215083/