I am doing a very simple docker image with a c++ written program that says hello.
I had to build the executable from a virtual machine, Ubuntu 18.04, x86-64.
I launched this executable on another machine, a Windows 10 64 bits via cmd, but it throws the following:
hello.exe n’est pas compatible avec la version de Windows actuellement exécutée. Vérifiez dans les informations système de votre ordinateur, puis contactez l’éditeur de logiciel.
(says it's not compatible with this windows version)
When launching it with git bash, it throws:
bash: ./hello.exe: cannot execute binary file: Exec format error
I was expecting this executable not to be runable from within a container, as per my understanding, it shares the host libraries. But surprisingly, it does work:
$ docker run hello
Hello! This message is coming from a container
I would like to know why it is working fine. I must have misunderstood something somewhere.
The dockerfile:
FROM scratch
ADD hello.exe /
CMD ["/hello.exe"]
The c++ program:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello! This message is coming from a container \n ";
return 0;
}
g++ command used to build the executable:
g++ -o hello.exe -static main.cpp