Docker CMD weirdness when ENTRYPOINT is a shell script

Here is a simple dockerfile

FROM centos:6.6 ENTRYPOINT ["/bin/bash", "-l", "-c"] CMD ["echo", "foo"] 

Unfortunately this will not work. Nothing happens when you start the created container that was built.
If you comment out ENTRYPOINT then it will work. However, if you set the ENTRYPOINT parameter to /bin/sh -c , it does not work again

 FROM centos:6.6 ENTRYPOINT ["/bin/sh", "-c"] CMD ["echo", "foo"] 

I thought it was the standard ENTRYPOINT for a container that didn't have a specific one, why doesn't it work?

Finally, it also works.

 FROM centos:6.6 ENTRYPOINT ["/bin/bash", "-l", "-c"] CMD ["echo foo"] 

Before I post a question, I wanted to see if I am doing something clearly wrong?
I use rvm inside my container, which requires the login shell to work properly.

+3
source share
1 answer

Please note that the standard entry point / cmd for the centos 6 official image:

  • no entry point
  • CMD ["/bin/bash"] only CMD ["/bin/bash"]

If you use the -c command, you need to pass one argument (which is the full command): "echo foo" .
Not a series of arguments ( CMD ["echo", "foo"] ).

As stated in the dockerfile CMD section:

If you use the CMD shell form, then <command> will execute in /bin/sh -c :

 FROM ubuntu CMD echo "This is a test." | wc - 

If you want to run <command> without a shell, you must express the command as a JSON array and provide the full path to the executable

Since echo is a built-in command in bash and C shell , a shell form is preferable here.

+1
source

Source: https://habr.com/ru/post/1234080/


All Articles