Exec into Pods/containers in kubernetes/Docker, created from images that does not contain bash pre-installed

10/7/2017

I'm trying to exec into haproxy-ingress pod created from this image, with this command:

kubectl -n kube-system exec -it haproxy-ingress-4122301161-bcd94 /bin/bash

Then I get this message

rpc error: code = 13 desc = invalid header field value "oci runtime error: exec failed: container_linux.go:247: starting container process caused \"exec: \\"/bin/bash\\": stat /bin/bash: no such file or directory\"\n"

Is there a way to exec into a container that is created using an image that does not have bash pre-installed?

-- codenio
alpine
docker
kubernetes
ssh

1 Answer

10/7/2017

Yes, it's not that uncommon for container not to have bash available. Often you will find that when bash is not there, /bin/sh still is, as is the case for the image you mention. Thus using kubectl -n kube-system exec -it haproxy-ingress-4122301161-bcd94 /bin/sh should suffice.

That aside, please mind for sake of clarity, you do not SSH into container, you execute a process within it.

-- Radek 'Goblin' Pieczonka
Source: StackOverflow