Hey guys, how are you doing? could you please share some advise regarding Comman . . .

Vladimir Shushkov:
hey guys, how are you doing? could you please share some advise regarding Commands used to run command in container, liveness or readiness probes? I found that I am doing sometimes mistakes on labs. When it’s required to run a command I sometimes put it with shell like /bin/sh -c <command>, but then in the solutions see that shell is not needed.
Probably it depends from the image like busybox or httpd. I think on the exam you have no access to docker registry. So what is the easy way to memorize when shell is required and where is not?

Vladimir Shushkov:
For example here the probes are not relying on the shell

Vladimir Shushkov:

image.png

mjv:
difference between ls /usr/local/apache2/htdocs and sh -c 'ls /usr/local/apache2/htdocs is that latter will spawn ls cmd in new shell(so one additional process in container).The thing is that some images don’t have sh at all so you cannot enter to its container (there are other ways though) with sh
Apart from that you don’t need to memorize anything as the outcome will be the same

mjv:
and for probes it is better to utilize httpGet or tcpSocket which will check some port/path instead of file existance

Vladimir Shushkov:
thank you @mjv That’s right, that some images don’t have sh, but how do you know during the exam if shell is there or not?

Vladimir Shushkov:
I think it’s possible to review docker repo for the image

Vladimir Shushkov:
but on the exam it’s not possible

Vladimir Shushkov:
yesterday I was doing Mock2 lab and there was a question about pod with image whalesay. On the task there was - Run command “Whale say CKAD is cool!”

mjv:
you can check docker/crictl history of the image to check base image layers but do you really need to know in advance if the image has sh or not, you can try to access to it via k exec -it ... -- sh

Vladimir Shushkov:
so I just used the command [“Whale”, “say”, “CKAD”, “is”, “cool!”]

Vladimir Shushkov:
but it turned out that it was wrong since the correct answer is sh -c "Whale say… "

mjv:
probably it was requested to print (use echo) and cause it has ! as last char you had to use sh -c

Vladimir Shushkov:
thanks @mjv Looks like for unknow images (not alpine for example) the easiest way us to run quickly a test pod as check with k exec

Alistair Mackay:
Hi @Vladimir Shushkov

Whether or not to use sh -c depends on what is going to be executed.

If the command is a shell script, which usually means that the question has asked to execute a string of commands separated by ; then you need sh -c. An example of such would be

[ "sh", "-c", "while true ; do echo $(date) &gt; /var/log/date.log ; sleep 10 ; done" ]

If the command is a standalone program file, like sleep ls, tail , cat, curl etc. then sh -c is not required e.g.

[ "sleep", "4800" ]

or

[ "tail", "-f", "/var/log/messages" ]

Alistair Mackay:
And in your example above, it would be

[ "whalesay", "CKAD is cool!" ]

whalesay is an executable program, and `CKAD is cool!" is the argument, what the whale will say.