3 min read | by Jordi Prats
While building a container using alpine as a base image we can get a not found error while trying to execute a file that doesn't make much sense:
$ docker run -it test /usr/local/bin/example-app exec /usr/local/bin/example-app: no such file or directory
As a reference for this example I'm building the image using the following Dockerfile:
FROM golang:1.18.3 as builder WORKDIR /build ADD . /build RUN make all FROM alpine:latest COPY --from=builder /build/example-app /usr/local/bin
The file have the correct permissions to be executes:
$ docker run -it test ls -l /usr/local/bin/example-app -rwxr-xr-x 1 root root 43434977 Nov 10 19:21 /usr/local/bin/example-app
We can even check with file that it really is an executable:
$ docker run -it test file /usr/local/bin/example-app /usr/local/bin/example-app: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, Go BuildID=lS3JON4J0nXBp2Z8OsMY/LukFvNH5JW5C08zFWRbL/9Px4OAp_95wJEUVDA5pX/Cmzbv3KWAAOCiYSI2-dX, not stripped
We won't be able to execute it, not even spawning a shell into the container (docker exec) or running an interactive one:
$ docker run -it test sh /app-data # cd /usr/local/bin/ /usr/local/bin # ls example-app /usr/local/bin # ls -la total 86196 drwxr-xr-x 1 root root 4096 Nov 10 19:22 . drwxr-xr-x 1 root root 4096 Aug 9 08:49 .. -rwxr-xr-x 1 root root 43434977 Nov 10 19:21 example-app /usr/local/bin # ./example-app sh: ./example-app: not found
On alpine containers, having the not found error is a typical symptom of dynamic link failure. We need to bear in mind that alpine uses the musl libc library so if the executable is looking for glibc executables it won't find them.
To be able to use binaries built to use glibc with musl, we can create symbolic links for the paths libraries they are looking for: There's a package already available that will do that for us:
apk add libc6-compat
Alternatively, we can change the base image to use one that doesn't use the musl library as well, such as Debian to completely avoid the problem:
FROM golang:1.18.3 as builder WORKDIR /build ADD . /build RUN make all FROM debian:11-slim COPY --from=builder /build/example-app /usr/local/bin
Posted on 14/11/2022