Docker exec用户进程中的Golang应用导致“没有此类文件或目录”

I am trying to create the docker image of an app that was developed in Go. I have the binary called myapp, and if I execute it then it work correctly, I execute it with:

./myapp

Then, take that bin and put it alone in a directory called mydirectory and inside I put this dockerfile:

# iron/go is the alpine image with only ca-certificates added
FROM iron/go

WORKDIR /

# Now just add the binary
ADD myapp /

ENTRYPOINT ["./myapp"]

and then I create the docker image by typing:

docker build -t myDockerHubUser/myapp .

Then, when I run the image I get this message:

standard_init_linux.go:185: exec user process caused "no such file or directory"

What does it mean? I found some post related with the same message but the thing is that my bnary is executed correctly without any problems

Inside the container /myfile doesn't have the permission for execution. You have to do a chmod +x /myfile inside the dockerfile. Just add following statement before ENTRYPOINT line.

RUN chmod +x /myfile

You have to build the binary inside docker not in your machine.

FROM golang

ADD ./ /go/src/app

WORKDIR /go/src/app

RUN go get ./

RUN go build

CMD app

You most likely either:

  • use the binary for the wrong platform
  • the binary is not statically linked (has not all the necessary libraries)

You can use CGO_ENABLED=0 to build your binary statically.