0

When mounting a file into a container, I am able to see it with ls or cat but I can't execute it.

What am I doing incorrectly? My files seem to have correct permissions and are obviously executable, I don't know what could cause this.

See the exemple below, where I try to mount gcc into the container and execute it. Here i used, alpine but the result is similar with other images.

$ sudo docker run --rm -it --mount  type=bind,source="./wrapper",target="/wrapper" alpine  ls -al /wrapper && /wrapper  
-rwxr-xr-x    1 root     root         17528 Jul 13 14:12 /wrapper
zsh: aucun fichier ou dossier de ce type: /wrapper

Maxime B.
  • 1,116
  • 8
  • 21
  • It returns `-rwxr-xr-x 1 root root 17528 13 juil. 16:12 ./wrapper`, i.e all. I need to use docker though – Maxime B. Jul 18 '23 at 13:12

1 Answers1

1

sudo docker run --rm -it --mount type=bind,source="./wrapper",target="/wrapper" alpine ls -al /wrapper && /wrapper

Executes:

sudo docker run --rm -it --mount  type=bind,source="./wrapper",target="/wrapper" alpine ls -al /wrapper 

which finishes successfully, so the shell that you are typing the commands into then executes another completely separate unrelated to docker command:

/wrapper

If you want to execute it in docker pass it all to docker. && in shell chains the commands.

docker run --rm -it --mount  type=bind,source="./wrapper",target="/wrapper" alpine sh -c 'ls -al /wrapper && /wrapper'

Consider researching an introduction to shell scripting and command chaining and quoting in particular.

Additionally, note, that you are running alpine linux. The binary is incompatible with musl C standard library and can't be run with alpine. Consider re-evaluating what exactly are you doing and researching what is alpine linux and how it differs, what is musl and how it differs from glibc, why bringing binary from host into docker is a bad idea, and consider just installing gcc into the image inside.

What am I doing incorrectly?

You are assuming shared library compatibility between your host system and a docker container. The whole idea of docker is to provide a layer of separation, so you don't have to deal with library compatibility. Consider using only binaries compiled specifically for the libraries inside the container - i.e. install and build them inside the container only and do not bring them from the host system.

The "why on alpine linux I get not found" error has been asked on this forum countless times. See Docker Alpine executable binary not found even if in PATH

KamilCuk
  • 120,984
  • 8
  • 59
  • 111
  • You are right. That was not the main issue though because wrapper is not found anyway `docker run --rm -it --mount type=bind,source="./wrapper",target="/wrapper" alpine sh -c 'ls -al /wrapper && /wrapper' -rwxr-xr-x 1 1000 1000 17528 Jul 13 14:12 /wrapper sh: /wrapper: not found` It also fails if I only do `/wrapper`. – Maxime B. Jul 18 '23 at 13:19
  • Please kindly see the note. – KamilCuk Jul 18 '23 at 13:20