I've created the following Dockerfile:
FROM ubuntu:20.04 as install
RUN apt update && \
apt -y install iputils-ping
FROM gcr.io/distroless/base-debian11
COPY --from=install /usr/bin/ping ./ping
COPY --from=install /lib/x86_64-linux-gnu/libcap.so.2 /lib/x86_64-linux-gnu/libcap.so.2
COPY --from=install /lib/x86_64-linux-gnu/libidn2.so.0 /lib/x86_64-linux-gnu/libidn2.so.0
COPY --from=install /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libc.so.6
COPY --from=install /lib/x86_64-linux-gnu/libunistring.so.2 /lib/x86_64-linux-gnu/libunistring.so.2
COPY --from=install /usr/lib/x86_64-linux-gnu/libgcrypt.so.20 /usr/lib/x86_64-linux-gnu/libgcrypt.so.20
COPY --from=install /usr/lib/x86_64-linux-gnu/libgpg-error.so.0 /usr/lib/x86_64-linux-gnu/libgpg-error.so.0
ENTRYPOINT ["./ping"]
But I don't understand why it doesn't work. I think that maybe the container stops before the process finishes.
$ docker run --rm distroless-ping 127.0.0.1
$ # no output from the run
At least, if I run it with no arguments I get the output:
$ docker run --rm distroless-ping
./ping: usage error: Destination address required
What's the issue here? I've tried using Docker's CMD
instead of ENTRYPOINT
but I got the same problem.
I don't know what
gcr.io/distroless/base-debian11
is, exactly, but it looks as if it includes an incompatible runtime loader. If we copy the dynamic loader from the Ubuntu image......then it seems to work as expected:
This makes the final
Dockerfile
look like:Note that with one additional library you can build the final image from
scratch
instead ofgcr.io/distroless/base-debian11
: