【发布时间】:2022-12-15 01:27:54
【问题描述】:
我正在尝试在 AWS Lambda 上运行 Docker 容器。图像构建良好,我可以在本地毫无问题地运行它。在 AWS 中触发函数时,出现依赖项错误。最近的一个是:
An assembly specified in the application dependencies manifest (MyProject.deps.json) was not found:
package: 'System.Drawing.Common', version: '5.0.0'
path: 'runtimes/unix/lib/netcoreapp3.0/System.Drawing.Common.dll'
查看 MyProject.deps.json,我确实看到了对这个程序集的引用,如下所示:
"System.Drawing.Common/5.0.0": {
"dependencies": {
"Microsoft.Win32.SystemEvents": "5.0.0"
},
"runtime": {
"lib/netcoreapp3.0/System.Drawing.Common.dll": {
"assemblyVersion": "5.0.0.0",
"fileVersion": "5.0.20.51904"
}
},
"runtimeTargets": {
"runtimes/unix/lib/netcoreapp3.0/System.Drawing.Common.dll": {
"rid": "unix",
"assetType": "runtime",
"assemblyVersion": "5.0.0.0",
"fileVersion": "5.0.20.51904"
},
"runtimes/win/lib/netcoreapp3.0/System.Drawing.Common.dll": {
"rid": "win",
"assetType": "runtime",
"assemblyVersion": "5.0.0.0",
"fileVersion": "5.0.20.51904"
}
}
},
检查我的 Docker 图像后,dotnet publish 似乎正在发布 runtimeTargets 路径中的所有内容除了对于第一个文件夹runtimes:
- 预期:
<root-of-my-app-in-docker>/runtimes/unix/lib/netcoreapp3.0/System.Drawing.Common.dll - 实际:
<root-of-my-app-in-docker>/unix/lib/netcoreapp3.0/System.Drawing.Common.dll
它为什么要这样做?
在本地运行 dotnet publish -o publish 会生成一个具有预期目录结构的 publish 文件夹。
这是我的 Dockerfile:
FROM public.ecr.aws/lambda/dotnet:5.0 as aws
WORKDIR /var/task
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY . .
WORKDIR /src/MyProject/src/MyProject
RUN dotnet restore "MyProject.csproj"
RUN dotnet build "MyProject.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "MyProject.csproj" -c Release -o /app/publish
FROM aws as final
WORKDIR /var/task
COPY --from=publish app/publish/* ./
CMD [ "MyProject::MyProject.Function::FunctionHandler" ]
虽然我没有尝试过,但我猜我可以通过手动将运行时目标复制到我手动创建的 runtimes 文件夹来在我的 Dockerfile 中解决这个问题。
- 但我为什么必须这样做?
- 为什么
dotnet publish创建一个引用不存在的文件的清单? - 我是否只是在我的 Dockerfile 中遗漏了导致此问题的内容?
【问题讨论】:
标签: c# docker aws-lambda .net-5