我正在尝试构建和运行.Net Core应用程序的docker映像。
这是我到目前为止尝试过的:
使用以下命令发布应用程序
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
答案 0 :(得分:1)
按照@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"]
现在,它可以正常工作了。