0

I use cross compile to compile a linux version binary on Mac.

GOOS=linux GOARCH=amd64 go build

Also tried the other command that I found on stack overflow.

GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o targetBinary

This binary can run in Linux VM. But when I copy this binary to a linux docker container and run it. It can not run anymore.

My docker file is like this

FROM oraclelinux:7.5
COPY targetBinary /

I also use ldd to check target and docker reports this result

[root@7578c118fe27 /]# ldd targetBinary
    not a dynamic executable
wzf1943
  • 121
  • 1
  • 9
  • What does it say when you try to execute the binary in docker? – JimB Feb 26 '19 at 01:07
  • Nothing outputs – wzf1943 Feb 26 '19 at 01:11
  • 1
    If there's no output, it doesn't seem like there's an error starting execution then. A static binary should run the same on most linux systems. You need to add some more debugging to see what's going on. – JimB Feb 26 '19 at 01:14
  • But run this binary in linux VM works well. Nothing weird happened – wzf1943 Feb 26 '19 at 01:22
  • It seems like the "targetBinary" is missing a file type? – hewiefreeman Feb 26 '19 at 02:26
  • @newplayer65: what is a "file type" and how could it be missing? – JimB Feb 26 '19 at 18:32
  • @wzf1943: the fact that it runs on another VM is further evidence that there's nothing wrong with the binary. You need add more debugging to figure why it's exiting early. What was the exit code? What does it do under strace? Does it require any particular files or resources form the system? If you want help with this, we need to have an [mcve], or at least a lot more information. – JimB Feb 26 '19 at 18:34

0 Answers0