I want add shell
or bash
to my image to execute installation command.
I have copied the /bin/bash
on my VM on to my image on Dockerfile
:
COPY /bin/bash /bin/
But when I execute the docker command:
docker run -it --entrypoint "/bin/bash" <my_image>
Then I get the following error :
/bin/bash: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
Thanks for your help
3
Answers
That’s because you’re trying to use dynamic-compiled
bash
in indocker
withoutglibc
support.TL;DR
bash-static
instead of classicbash
You may download it or run
./build.sh
bash
foralpine
: add this line to yourDockerfile
:RUN apk add --no-cache bash
Alpine
is amusl
-based distroMany docker images are built with
alpine
as base image:alpine
(usually) is small & fast:Here are the sizes of the images of popular operating systems.
source: A Breakdown of Operating Systems of Dockerhub
musl
doesn’t containlibtinfo
See more about difference between
glibc
andmusl
Functional differences from glibcP.S. you can run
bash-static
even in empty container fromscratch
You could probably add busybox in now.
Google’s distroless images have versions tagged
debug
, which containbusybox
executable (withsh
bundled in).If you have to, you can arguably use them even in production (which defeats the purpose of increased security – such as hiding environment variables and protecting scripted apps code).
Usage example of the
distroless/base
image withdebug
tag:You can do it by copying the statically compiled shell from official
busybox
image in a multi-stage build in your Dockerfile. Or justCOPY --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 ofbusybox
as well.Example:
The single-line
COPY --from
directly from image would also work: