3

This is...kinda insane?

/bin # echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/bin # ./app 
sh: ./app: not found
/bin # ls -lha | grep app
-rwxr-xr-x    1 root     root       48.3M May  9 09:48 app
/bin # pwd
/bin
/bin # app
sh: app: not found

the docker image was created using multistage build:

FROM golang AS builder
WORKDIR /go/src/github.com/nmiculinic/app/
RUN go get -u github.com/golang/dep/cmd/dep
COPY Gopkg.lock Gopkg.toml ./
RUN dep ensure -vendor-only
COPY . .
RUN GOOS=linux go install ./cmd/app

FROM alpine:latest
RUN apk --no-cache add ca-certificates && update-ca-certificates

COPY --from=builder /go/bin/ /bin
COPY config /etc/app/
ENTRYPOINT ["/bin/app"]

The app is clearly in the PATH, all other things from path works, but mine doesn't. I just don't see how is this possible.

nmiculinic
  • 2,224
  • 3
  • 24
  • 39

1 Answers1

5

I encountered this issue, which turns out to be related to dependencies. My app was written in C, and it has several dynamic dependencies.

You can use:

ldd /bin/app

to check if your program has dynamic dependencies. If it has, then install the required dependencies and the problem will be solved.

Or you can use gcc flags to compile your program as a static program.

Remember to tell how you solved this problem :)

Update

You can also refer to this link, in which, the program are dynamically lined with network related dependencies. Go-compiled binary won't run in an alpine docker container on Ubuntu host

Arith
  • 372
  • 1
  • 8
  • This was weird...if I used golang:apline as builder image, now it works – nmiculinic May 09 '18 at 15:20
  • It's because of `golang:alpine` contains the regular dynamic dependencies go programs need. – Arith May 09 '18 at 16:31
  • I see... I though golang is statically complied, but apparently there are some deps you cannot statically compile? Or maybe I misunderstood something – nmiculinic May 10 '18 at 11:16