Docker: Cannot execute binary file

From this forum thread:

This error occurs when you use a shell in your entrypoint without the “-c” argument

So, if you change your Dockerfile to end with

ENTRYPOINT [ "/bin/bash", "-l", "-c" ]

then you can run binary files.

Note the purpose of the options for /bin/bash, from the manpage:

  • -l: Make bash act as if it had been invoked as a login shell

  • -c: If the -c option is present, then commands are read from the first non-option argument command_string. If there are arguments after the command_string, the first argument is assigned to $0 and any remaining arguments are assigned to the positional parameters. The assignment to $0 sets the name of the shell, which is used in warning and error messages.

Additionally, this article is a worthwhile read on how to use both ENTRYPOINT and CMD together, and what their differences are.

EDIT: Here’s another article that goes into a trivial (but clearer than the first article) example using the echo shell builtin.

EDIT: Here’s an adaptation of the trivial example from the second article I linked:

FROM ubuntu
ENTRYPOINT [ "/bin/bash", "-l", "-c" ]
CMD [ "ls" ]
$ docker build -t test .

$ docker run --rm test
bin
boot
...
var

$ docker run --rm test "ls etc"
adduser.conf
alternatives
apt
...
update-motd.d
xattr.conf

Note the " around ls /etc. Without the quotes, the argument /etc doesn’t seem to be passed to the ls command as I might expect.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)