I Have written a very simple c++ hello world program
#pragma once
#include <iostream>
#include <fstream>
int main()
{
std::cout << "Hello Docker world!\n";
return 0;
}
This is build as a release x64 windows console application and thus produces an exe
than I dockerize this program using the following dockerfile
FROM microsoft/windowsservercore
ADD ./DockerHello.exe /DockerHello.exe
# Run exe when the container launches
CMD C:\DockerHello.exe
However when i use docker run it will show nothing and when i use docker ps -a I see that it has exited with code 3221225781
From some online searching I understand that this apparently means that I am missing some dll or so, but I have no idea how to find out which?
Can anybody help me? Or tell me how I can get a simple c++ console application working in docker?
As confirmed in the comments, the issue stems from the runtime library not being present on the Docker image for code compiled from MSVC.
To solve this, you may either:
/MT
flag.The /MT
flag (or variants) must be passed to msbuild, which through Visual Studio can be done as follows (from Microsoft's documentation):
Open the project's Property Pages dialog box. For details, see How to: Open Project Property Pages. Expand the C/C++ folder. Select the Code Generation property page. Modify the Runtime Library property.
To install the correct runtime, you must install the redistributable while building of the docker image.
ADD $url /vc_redist.exe
RUN C:\vc_redist.exe /quiet /install
For Visual Studio, these are the correct URL (as of today's date, feel free to edit to update):
Where the $url
is the path to the correct Visual Studio Redistributable (links provided below):
As the OP notes in the comments, the microsoft/nanoserver
image is sufficient when using static runtime linking, however, if using shared runtime linking, you should use the microsoft/windowsservercore
image, otherwise, the installation of the redistributable fails.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With