Entrypoint in Docker

I am using the following Dockerfile

FROM alpine
MAINTAINER sahil
ENTRYPOINT ["/bin/sh",“ls -l”]

Query : I am expecting output for ls -l but I get following

bin/sh: can’t open ‘ls -l’

What is wrong ??

ls -l is an unknown binary, so cannot be found and opened.

Could write ENTRYPOINT ["/bin/sh", "ls", "-l"], then it would execute the binary ls and provide it the argument -l

Still says cannot open “ls”

you do not need the shell. So also could go with just ENTRYPOINT ["ls", "-l"]

Ya ,that works. What is the reason ? and why I cannot define ENTRYPOINT [“ls -l”]

cause there is just a binary called ls. No binary called ls -l.
You could ENTRYPOINT ["sh", "-c", "ls -l"]. Then the Shell (sh) will see ls -l as a command and split it into program and arguments to finally just consider ls as binary and not the whole string.

1 Like