Windows 从docker容器执行exe内部打印

Windows 从docker容器执行exe内部打印,windows,docker,Windows,Docker,Program.exe类似于: int main() { printf("Hey, there!\n"); return 0; } FROM mcr.microsoft.com/windows/servercore:2004 USER ContainerAdministrator COPY Debug/. ./bin/ COPY log/. ./log/ RUN Powershell.exe -Command $ErrorActionPreference

Program.exe类似于:

int main()
{
    printf("Hey, there!\n");

    return 0;
}
FROM mcr.microsoft.com/windows/servercore:2004
USER ContainerAdministrator
COPY Debug/. ./bin/
COPY log/. ./log/
RUN Powershell.exe -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x86.exe -OutFile 'c:\vc_redist.x86.exe' ; Start-Process c:\vc_redist.x86.exe -ArgumentList '/passive' -RedirectStandardOutput 'c:\Windows\System32' -Wait ; Remove-Item c:\vc_redist.x86.exe -Force
Dockerfile类似于:

int main()
{
    printf("Hey, there!\n");

    return 0;
}
FROM mcr.microsoft.com/windows/servercore:2004
USER ContainerAdministrator
COPY Debug/. ./bin/
COPY log/. ./log/
RUN Powershell.exe -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x86.exe -OutFile 'c:\vc_redist.x86.exe' ; Start-Process c:\vc_redist.x86.exe -ArgumentList '/passive' -RedirectStandardOutput 'c:\Windows\System32' -Wait ; Remove-Item c:\vc_redist.x86.exe -Force
当我运行容器并导航到C:/bin以执行Program.exe时,控制台上不会打印任何内容,Program.exe会无误退出。 Program.exe所依赖的所有DLL和LIB都正常(通过procmon和dependency walker验证),并且vcredist已正确安装

docker logs 
命令不记录任何内容

Program.exe在主机中执行良好


在这种情况下如何将f打印到控制台?

在生成映像时执行RUN,而不是在容器运行时使用ENTRYPOINT或CMD。看看最好的练习

您可以使用ENTRYPOINT来设置main命令,并使用CMD来设置像这样的默认选项,以遵循最佳实践

ENTRYPOINT ["command"]
CMD ["param", "param"]

谢谢你的快速回复!使用ENTRYPOINT进行了测试,但结果相同抱歉,我不熟悉Windows容器,我没有看到您想要运行Program.exe。如何使用docker exec执行它?docker run-it test powershell