问题描述
我正在使用VS2019,并且在手动创建的docker容器中以及通过从Visual Studio生成的存根中部署了运行良好的服务。 VS的发布实现工作正常,但是,当我从VS的调试模式运行容器时,由于缺少其依赖项之一,服务会引发异常。
Dockerfile :
RUN apt-get update && apt-get install handbrake-cli -y //This is the only line which has been added to the VS2019 dockerfile stub.
ENTRYPOINT ["dotnet","myapp.dll"]
如果我启动docker exec / CLI,则在Debug下观察到的行为:
# apt-get install handbrake-cli
Reading package lists... Done
Building dependency tree
Reading state @R_170_4045@ion... Done
E: Unable to locate package handbrake-cli
# apt-get update && apt-get install handbrake-cli
...
Reading state @R_170_4045@ion... Done
The following additional packages will be installed:
...
# HandBrakeCLI
[14:11:51] hb_init: starting libhb thread
[14:11:51] thread 7eff9c606700 started ("libhb")
Missing input device. Run HandBrakeCLI --help for Syntax.
HandBrake has exited.
#
显而易见,在调试模式下,我的Dockerfile似乎没有应用更新和安装handbrake-cli的行。我已经尝试将更新拆分并安装到单独的运行中,但是相同的行为仍然存在。在这一点上,我对自己在做错什么感到有些困惑,因为发行版本不会受到此问题的困扰。
解决方法
C#Discord中的Cisien:
我猜想VS会跳过最后阶段,而代之以附加调试器
解决方案将安装移动到第二行,以便:
FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim AS base
RUN apt-get update && apt-get install -y handbrake-cli && apt-get clean
类似地,建议使用apt-get clean来减小图像大小。
非常感谢Cisien的及时准确的答复!