Docker CMD can't find files installed with Dockerfile?

Docker version 20.10.17, build 100c701

My Dockerfile

FROM ubuntu:22.04

COPY / .

COPY / /home/

RUN chmod +x /home/

VOLUME ["/home/volume/bla"]

EXPOSE 3677 3678


CMD ["sh /home/"]

set -e
echo $@
exec "$@"

I build the project
docker build /home/project/docker/ -t root/project

Then I run it docker run --user root -it --name project-container root/project

It logs $@ then exec $@

sh /home/
/ line 25: /sh /home/ No such file or directory

Why does it not find the script? this is driving me nuts.

Also tried: CMD ["/usr/bin/sh /home/"] in the Dockerfile but I get the same result


Have you seen this:

The CMD instruction has three forms:

CMD ["executable","param1","param2"] (exec form, this is the preferred form)
CMD ["param1","param2"] (as default parameters to ENTRYPOINT)
CMD command param1 param2 (shell form)

I belive you’re mixing 1 & 3

1 Like

Because it does not exist. The answer is what @terpz pointed out. When you use the exec syntax which makes CMD to be the argument of the entrypoint, every entry that you put between quotation marks are considered to be one file path not a command an its arguments.

The correct way is:

CMD ["sh", "/home/"]

You really want to use the exec form, because the other would not be the argument of the entrypoint and could work differently or not work at all.

And you can probably use the CMD without the “sh” part:

CMD ["/home/"]

Furthermore, your ENTRYPOINT and CMD combination would result in the command / "sh /home/", as CMD will be the argument to ENTRYPOINT.

If you declare CMD as CMD [/"home/"], the container will execute / /home/

Note: make sure both scripts are executable. For / you depend on the +x permissions being set on the host, as you don’t set in your Dockerfile explicitly, like you did for /home/