I'm trying to build the below Dockerfile, but it keeps failing on RUN ocp-indent --help
saying ocp-indent: not found The command '/bin/sh -c ocp-indent --help' returned a non-zero code: 127
FROM ocaml/opam WORKDIR /workdir RUN opam init --auto-setup RUN opam install --yes ocp-indent RUN ocp-indent --help ENTRYPOINT ["ocp-indent"] CMD ["--help"]
I bashed into the image that ran before it via docker run -it <image id> bash -il
and ran ocp-indent --help
and it ran fine. Not sure why it's failing, thoughts?
This is a PATH related issue and profile. When you use sh -c
or bash -c
the profile files are not loaded. But when you use bash -lc
it means load the profile and also execute the command. Now your profile may have the necessary path setup to run this command.
Edit-1
So the issue with the original answer was that it cannot work. When we had
ENTRYPOINT ["/bin/bash", "-lc", "ocp-indent"] CMD ["--help"]
It finally translates to /bin/bash -lc ocp-indent --help
while for it to work we need /bin/bash -lc "ocp-indent --help"
. This cannot be done by directly by using command in entrypoint. So we need to make a new entrypoint.sh
file
#!/bin/sh -l ocp-indent "$@"
Make sure to chmod +x entrypoint.sh
on host. And update the Dockerfile to below
FROM ocaml/opam WORKDIR /workdir RUN opam init --auto-setup RUN opam install --yes ocp-indent SHELL ["/bin/sh", "-lc"] COPY entrypoint.sh /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"] CMD ["--help"]
After build and run it works
$ docker run f76dda33092a NAME ocp-indent - Automatic indentation of OCaml source files SYNOPSIS
Original answer
You can easily test the difference between both using below commands
docker run -it --entrypoint "/bin/sh" <image id> env docker run -it --entrypoint "/bin/sh -l" <image id> env docker run -it --entrypoint "/bin/bash" <image id> env docker run -it --entrypoint "/bin/bash -l" <image id> env
Now either you bash has correct path by default or it will only come when you use the -l
flag. In that case you can change the default shell of your docker image to below
FROM ocaml/opam WORKDIR /workdir RUN opam init --auto-setup RUN opam install --yes ocp-indent SHELL ["/bin/bash", "-lc"] RUN ocp-indent --help ENTRYPOINT ["/bin/bash", "-lc", "ocp-indent"] CMD ["--help"]