简体   繁体   中英

Docker not running .exe file

I have a question regarding dockerizing C/C++ project. I am using visual studio compiler image because I have a lot of environment trouble with running MinGW compiler.

I confirmed project using visual studio compiler image and building solution perfectly, but I'm seeing problem with actually running generated.exe file in docker container environment.

Following is my dockerfile code:

# 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 &&

I copied it from microsoft official website here: https://devblogs.microsoft.com/cppblog/using-msvc-in-a-docker-container-for-your-c-projects/

and following is my output

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>

After building, it instantly terminated without printing out program output. Instead, I tried going into docker environment and running.exe by myself.

and following is output:


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

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

it didn't print out error messages. It works perfectly fine when I opened.exe file on local computer. I am not sure how I should resolve problem since there isn't error message that I can see and fix.

I had the same issue with a Rust executable on a Docker image based on windows/servercore:ltsc2019 . I used Dependency Walker to open the executable and saw that it depended on vcruntime140.dll . Then after downloading and installing the Visual C++ 2015 Redistributable package within the Docker container, my executable ran correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM