On Day #7 lets see how to explore the contents of the container. How does ssh work in the containerized world?
When working with linux hosts, you can explore them by using ssh. Connect to the remote IP or host and work as if you were doing it locally – modulo restrictions, latency, missing tools.
On the container level, OpenShift client provides the oc rsh command to allow you to get a shell session in the pod.
NAME READY STATUS RESTARTS AGE
nodejs-1-8w958-debug 0/1 Completed 0 23d
nodejs-1-build 0/1 Completed 0 23d
nodejs-2-nh25m 1/1 Running 3 9d
nodejs-2-zhgkr 1/1 Running 1 22h
<we are in!>
By default the /bin/sh is used for shell command. You can use
oc rsh <pod> --shell=/bin/bash – will create a bash shell if you have it installed in the container. Otherwise it fails.
oc rsh <pod> -c <container> – as usual when the pod interaction is in scope, you can specify the container that should be used for the connection.
It is also possible to get the shell directly from the WebUI. After selecting one of the pods, you have access to Terminal tab. This is what you are looking for if you want to quickly execute some commands in the pod.
oc rsh --help – as always worth checking for hidden gems.
https://docs.openshift.org/3.6/dev_guide/ssh_environment.html – some official documentation for the command
The commands were executed using minishift and the following client/server versions of OpenShift.
Thanks for reading the OpenShift morsels. To get updates about new articles, you can sign up to the newsletter below.
As a thank you message, you will also get access to OpenShift CLI CheatSheet listing most commonly used commands together with a short explanation.