Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Golang app in Docker exec user process caused "no such file or directory"

Tags:

docker

go

ubuntu

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

like image 280
Sredny M Casanova Avatar asked Mar 03 '18 02:03

Sredny M Casanova


2 Answers

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.

like image 191
Enrico Stahn Avatar answered Sep 21 '22 12:09

Enrico Stahn


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
like image 38
Mostafa Solati Avatar answered Sep 25 '22 12:09

Mostafa Solati