Docker未运行.exe文件

v440hwme  于 2022-12-17  发布在  Docker
关注(0)|答案(1)|浏览(156)

我有一个关于dockerizing C/C++项目的问题。我正在使用visual studio编译器映像,因为我在运行MinGW编译器时遇到了很多环境问题。
我确认项目使用Visual Studio编译器图像和构建解决方案完美,但我看到的问题,实际运行生成的.exe文件在Docker容器环境。
下面是我的dockerfile代码:

# escape=`

# Copyright (C) Microsoft Corporation. All rights reserved.
# Licensed under the MIT license. See LICENSE.txt in the project root for license information.

ARG FROM_IMAGE=microsoft/dotnet-framework:3.5-sdk-windowsservercore-1709
FROM ${FROM_IMAGE}

# Reset the shell.
SHELL ["cmd", "/S", "/C"]

# Set up environment to collect install errors.
COPY Install.cmd C:\TEMP\
ADD https://aka.ms/vscollect.exe C:\TEMP\collect.exe

# Install Node.js LTS
ADD https://nodejs.org/dist/v8.11.3/node-v8.11.3-x64.msi C:\TEMP\node-install.msi
RUN start /wait msiexec.exe /i C:\TEMP\node-install.msi /l*vx "%TEMP%\MSI-node-install.log" /qn ADDLOCAL=ALL

# Download channel for fixed install.
ARG CHANNEL_URL=https://aka.ms/vs/15/release/channel
ADD ${CHANNEL_URL} C:\TEMP\VisualStudio.chman

# Download and install Build Tools for Visual Studio 2017 for native desktop workload.
ADD https://aka.ms/vs/15/release/vs_buildtools.exe C:\TEMP\vs_buildtools.exe
RUN C:\TEMP\Install.cmd C:\TEMP\vs_buildtools.exe --quiet --wait --norestart --nocache `
    --channelUri C:\TEMP\VisualStudio.chman `
    --installChannelUri C:\TEMP\VisualStudio.chman `
    --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended`
    --installPath C:\BuildTools

# Execute commands once container runs
# Build solution using MSVC
ENTRYPOINT C:\BuildTools\Common7\Tools\VsDevCmd.bat &&

我复制它从微软官方网站在这里:https://devblogs.microsoft.com/cppblog/using-msvc-in-a-docker-container-for-your-c-projects/
以下是我的输出

C:\Users\cshim31\smarts-pxie-executive>docker run -v C:\Users\cshim31\smarts-pxie-executive:c:\smarts-pxie-executive -it buildtools2017native:2017 msbuild C:\smarts-pxie-executive\Project4.sln /p:Configuration=Debug /p:Platform=x64
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.0
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
Build started 3/10/2021 6:07:46 PM.
Project "C:\smarts-pxie-executive\Project4.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
  Building solution configuration "Debug|x64".
Project "C:\smarts-pxie-executive\Project4.sln" (1) is building "C:\smarts-pxie-executive\Project4.vcxproj" (2) on node 1 (default targets).
InitializeBuildStatus:
  Creating "x64\Debug\Project4.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
ClCompile:
  All outputs are up-to-date.
Link:
  All outputs are up-to-date.
  Project4.vcxproj -> C:\smarts-pxie-executive\x64\Debug\Project4.exe
FinalizeBuildStatus:
  Deleting file "x64\Debug\Project4.tlog\unsuccessfulbuild".
  Touching "x64\Debug\Project4.tlog\Project4.lastbuildstate".
Done Building Project "C:\smarts-pxie-executive\Project4.vcxproj" (default targets).

Done Building Project "C:\smarts-pxie-executive\Project4.sln" (default targets).

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.12

C:\Users\cshim31\smarts-pxie-executive>

构建后,它立即终止,没有打印出程序输出。相反,我尝试进入Docker环境,自己运行。exe。
输出如下:

C:\smarts-pxie-executive\x64\Debug>Project4.exe

C:\smarts-pxie-executive\x64\Debug>

它没有打印出错误消息。当我在本地计算机上打开.exe文件时,它工作得非常好。我不知道我应该如何解决问题,因为没有错误消息,我可以看到和修复。

cbjzeqam

cbjzeqam1#

基于windows/servercore:ltsc2019的Docker映像上的Rust可执行文件也遇到了同样的问题。我使用Dependency Walker打开可执行文件,发现它依赖于vcruntime140.dll。然后在Docker容器中下载并安装Visual C++ 2015 Redistributable包后,我的可执行文件正常运行。

相关问题