windows - 从Docker容器在exe内部执行打印

标签 windows docker

Program.exe类似于:

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

    return 0;
}
Dockerfile就像:
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在主机中可以正常执行。
在这种情况下如何打印到控制台?

最佳答案

当构建镜像而不是在容器运行时使用ENTRYPOINT或CMD执行RUN。看看最好的做法here

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
CMD C:/bin/Program.exe
您可以使用ENTRYPOINT来设置主命令,并使用CMD来设置默认选项,以遵循最佳实践
ENTRYPOINT ["command"]
CMD ["param", "param"]

关于windows - 从Docker容器在exe内部执行打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63349803/

相关文章:

c++ - 将 C++ (DLL) 项目转换为 COM DLL 项目

windows - 批处理 - 如果正在运行则终止程序,如果没有则启动它

linux - 在容器中运行 apt update && apt install -y sudo 失败

mongodb - 用于 mongo-1.5.5.tgz 的 pecl install mongo 命令产生无效的 tgz 错误

c - 在运行一些计算时写入 txt 文件

windows - Haskell 或 Elm 错误 : unknown public key OID

c# - 如何在 WebBrowser 控件中获取当前状态代码?

docker - 是否可以嵌套 docker/podman 容器

docker - 我的docker-compose从另一个文件夹中拾取文件,而不是从我运行命令的位置

docker - 有没有办法强制执行模块间依赖/初始化顺序?