You can do it by copying the statically compiled shell from official busybox
image in a multi-stage build in your Dockerfile. Or just COPY --from
it.
The static shell doesn't have so many dependencies, so it will work for a range of different base images. It may not work for some very advanced cases, but otherwise it gets the job done.
The statically compiled shell is tagged with uclibc
. Depending on your base image you may have success with other flavours of busybox
as well.
Example:
FROM busybox:1.35.0-uclibc as busybox
FROM gcr.io/distroless/base-debian11
# Now copy the static shell into base image.
COPY --from=busybox /bin/sh /bin/sh
# You may also copy all necessary executables into distroless image.
COPY --from=busybox /bin/mkdir /bin/mkdir
COPY --from=busybox /bin/cat /bin/cat
ENTRYPOINT ["/bin/sh", "/entrypoint.sh"]
The single-line COPY --from
directly from image would also work:
FROM gcr.io/distroless/base-debian11
COPY --from=busybox:1.35.0-uclibc /bin/sh /bin/sh
ENTRYPOINT ["/bin/sh", "/entrypoint.sh"]