Using Mac OSX (Sierra), I compiled a simple hello.c file (similar to the one on the GitHub repo). The executable runs fine from the Mac command line, but fails to run from within the container; I get the following error, "standard_init_linux.go:175: exec user process caused “exec format error”. What am I doing wrong?
(I understand that my little “hello” application could be built based on a full on Linux or Debian OS base image and probably work, but I’m trying to understand what’s the absolute minimal version of an application that I can build and as part of that process, I want to understand what the minimum environment for the Docker image to contain. If my hello.c application makes native Linux/Debian OS kernel calls, e.g write() and _exit, I would have assumed that it could execute this without any issues. In other words, I was assuming that Docker would be able to make this call directly to the host OS, in this case Debian. However, I tried the same exact thing using my Linux host OS and it fails with another error: panic: standard_init_linux.go:175: exec user process caused "no such file or directory" [recovered]
)
— hello.c —
#include <unistd.h> // _exit() and write(2); man -s2 write
#ifndef DOCKER_IMAGE
#define DOCKER_IMAGE "hello-world"
#endif
#ifndef DOCKER_GREETING
#define DOCKER_GREETING "Hello from Docker!"
#endif
const char message[] =
"\n"
DOCKER_GREETING "\n"
"This message shows that your C application appears to be working correctly.\n"
"\n";
int main() {
write(1, message, sizeof(message) - 1);
_exit(0);
}
I compile it on Mac OSX with:
build -o hello hello.c
$ ./hello
Hello from Docker!
This message shows that your C application appears to be working correctly.
I then build the Docker image with a minimal.docker file that looks like:
$ cat minimal.docker
FROM scratch
ADD hello /
CMD ["/hello"]
$ docker build -f minimal.docker .
Sending build context to Docker daemon 13.82 kB
Step 1/3 : FROM scratch
—>
Step 2/3 : ADD hello /
—> 56e31a943dde
Removing intermediate container 843df5833844
Step 3/3 : CMD /hello
—> Running in 1cfc46e8e0c4
—> 21c49c4ad4bf
Removing intermediate container 1cfc46e8e0c4
Successfully built 21c49c4ad4bf
Then I try to execute it with:
$ docker run 21c49c4ad4bf
And I get the following error:
standard_init_linux.go:175: exec user process caused “exec format error”
I’ve read things that suggest that I need to verify that I am trying to run a 64-bit executable with my 64-bit Mac OSX Sierra OS. And I am as can be seen with:
$ file hello
hello: Mach-O 64-bit executable x86_64
Here’s my Docker version:
$ docker version
Client:
Version: 1.13.0-rc4
API version: 1.25
Go version: go1.7.3
Git commit: 88862e7
Built: Sat Dec 17 01:34:17 2016
OS/Arch: darwin/amd64
Server:
Version: 1.13.0-rc4
API version: 1.25 (minimum version 1.12)
Go version: go1.7.3
Git commit: 88862e7
Built: Sat Dec 17 01:34:17 2016
OS/Arch: linux/amd64
Experimental: true
What am I doing wrong? I was expecting the Docker container to send the calls directly to the Mac OSX Debian kernel to execute.