3

I'm trying to follow the instructions on slimming my Docker files by using multi-stage builds. In particular, I try to copy over the built executable from the builder image into alpine:latest with the following Dockerfile:

FROM debian:stable-slim AS builder

RUN apt-get update && \
    apt-get install -y --no-install-recommends fp-compiler fp-units-fcl fp-units-net libc6-dev

COPY src /whatwg/wattsi/src
RUN /whatwg/wattsi/src/build.sh

FROM alpine:latest
COPY --from=builder /whatwg/wattsi/bin /whatwg/wattsi/bin

ENTRYPOINT ["/whatwg/wattsi/bin/wattsi"]

However, when I try to run the resulting docker image using docker run, I get the error

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

What is going on, and how do I fix this?

Domenic
  • 110,262
  • 41
  • 219
  • 271

1 Answers1

5

This question has come up multiple times, and this error seems to have many possible causes. Some are missing or wrong shebang instructions in any bash scripts, or Windows line endings in files copied to the volume. However, in my case, it for a different reason.

This error occurred because the built binary (/whatwg/wattsi/bin in the question) depends on the system having glibc installed. Presumably, when running, something is looking for the system's glibc, but Alpine Linux does not have glibc available. (Instead, it uses musl-libc, which is more minimal, but less popular.)

The easiest fix for this is to use a different base image that has glibc available. You could use the debian:stable-slim that you're using in the builder image (69.2 MiB), but a smaller one would be Google's Distroless base image gcr.io/distroless/base (16.9 MiB). This is still larger than alpine:latest (5.61 MiB) or the Distroless static image (1.82 MiB), but it's not bad.

There are probably other solutions, e.g. this question discusses ways to set up glibc on Alpine Linux. Or, you could figure out how to change your compiler/linker to link against the system libc (i.e., musl-libc on Alpine Linux), instead of assuming the existence of glibc specifically. But for my case, gcr.io/distroless/base worked perfectly.

Domenic
  • 110,262
  • 41
  • 219
  • 271
  • One important correction: Alpine doesn't have *glibc* (GNU libc) installed - it does have a libc. libc provides the standard C library and the POSIX API and therefore is builtin to any Linux distro. glibc is the defacto standard libc implementation. Alpine Linux builds on the musl-libc library, which is a minimal and strict POSIX libc implementation, and is indeed not compatible with glibc. – valiano May 26 '20 at 20:10
  • Thank you @valiano. I've updated the answer to be more along those lines. – Domenic May 28 '20 at 18:42