Run mounted readlink

$ cat docker-compose.yml 
        command: /bin/readlink /bin
        image: bash
            - /usr/bin/readlink:/bin/readlink

$ docker-compose run --rm test 
Creating tmputpywvkia7_test_run ... done
/usr/local/bin/ line 11: /bin/readlink: No such file or directory
ERROR: 127

Let’s do some in-depth analysis

$ ls -l /usr/bin/readlink
-rwxr-xr-x 1 root root 39328 feb  7  2022 /usr/bin/readlink

$ docker-compose run --rm test ls -l /bin/readlink
Creating tmputpywvkia7_test_run ... done
-rwxr-xr-x    1 root     root         39328 Feb  7  2022 /bin/readlink

Everything seems fine.
So where is the problem?

Finally, if they can serve some info

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.2 LTS
Release:	22.04
Codename:	jammy

$ docker --version
Docker version 20.10.25, build 20.10.25-0ubuntu1~22.04.1

$ bash --version | head -n 1
GNU bash, versione 5.1.16(1)-release (x86_64-pc-linux-gnu)

$ docker-compose run --rm test bash --version | head -n 1
Creating tmputpywvkia7_test_run ... done
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-musl)

Looks like the image is based on Alpine, which uses musl instead of glibc.
As such, binaries that depend on the glibc standard library will not work out of the box.

These options come to mind:
– use the readlink version that is included in the alpine core image, which is inherited by the bash image you use
– build your own image and install the gcompat package (apk add gcompat) to add a glibc compatibility layer
– build your own image and install the glbic library as third party package: GitHub - sgerrand/alpine-pkg-glibc: A glibc compatibility layer package for Alpine Linux

A container should be self contained. Binding binaries from the host into a container, and trying to run them kind of breaks this aspect, wouldn’t you agree? Especially if you try to run dynamically compiled binaries, that depend on libraries that may or may not exist in the image. It should work with static compiled binaries.

thanks for the infos