Docker Community Forums

Share and learn in the Docker community.

How to run an existing c/c++ binary executable as a docker container


(Praneethkapuganti) #1

I am new to container world and exploring options to run my application on a container.Here are the things that I am seeing
1.When I include compiling and building the C/C++ binary as part of docker image itself, it works fine with out any problems. Container starts and everything works fine.
2. If I try to run an already compiled and existing binary using CMD ["./helloworld"] in a container It throws me this error
standard_init_linux.go:185: exec user process caused “exec format error”.

Any ideas of how to get out of this problem? This seems like a basic problem that would have been solved already

Here is my dockerfile:
FROM ubuntu
COPY . /Users/test//Documents/CPP-Projects/HelloWorld-Static
WORKDIR /Users/test/Documents/CPP-Projects/HelloWorld-Static
CMD ["./build/exe/hellostatic/hellostatic"]

Hers is my exe
gobjdump -a build/exe/hellostatic/hellostatic
build/exe/hellostatic/hellostatic: file format mach-o-x86-64

Here is the error:
docker run test
standard_init_linux.go:185: exec user process caused “exec format error”

(David Maze) #2

You’re trying to run a Mac binary on a Linux VM/container. If you build the binary within a container (doesn’t have to be the same container) then it’ll be built in a Linux environment and the operating system will match.