59

I am running the container hypriot/rpi-busybox-httpd

I am trying to ssh to docker container: but it is giving error :

pi@raspberrypi:~ $ docker exec -it cc55da85b915 bash
rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:247: starting container process caused "exec: \"bash\": executable file not found in $PATH"

pi@raspberrypi:~ $ docker exec -it cc55da85b915 sh
rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:247: starting container process caused "exec: \"sh\": executable file not found in $PATH"

am I doing the right away ?

Ciasto piekarz
  • 7,853
  • 18
  • 101
  • 197
  • 7
    What happens if you specify the full path to `bash`, _e.g._ `docker exec -it cc55da85b915 /bin/bash` (or `/usr/local/bin/bash`, or wherever `bash` is located in that image)? – Castaglia Feb 04 '17 at 20:35
  • @Castaglia that should probably be an accepted answer :) – Zathrus Writer Feb 04 '17 at 22:22
  • 1
    @Castaglia @ZathrusWriter I tried `$ docker exec -it baa50167dd75 /bin/bash` but I still got this error `rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:247: starting container process caused "exec: \"/bin/bash\": stat /bin/bash: no such file or directory"` – Ciasto piekarz Feb 05 '17 at 01:13
  • 2
    OK, that's progress. From the [rpi-busybox-httpd](https://github.com/hypriot/rpi-busybox-httpd) repo, it looks your image is built with the [dockerize](https://github.com/larsks/dockerize), which installs _only_ the files needed for running. As this is the case, I suspect you will not be able to exec any kind of shell on that image. – Castaglia Feb 05 '17 at 03:12
  • well, I doubt, after lots of troubleshooting I tried : `docker exec -it baa50167dd75 /bin/bash` and now I get this error. `could not read CA certificate "/home/pi/.docker/ca.pem": open /home/pi/.docker/ca.pem: no such file or directory` so that means I need CA certificate for docker. on my raspberry pi `.docker` folder is not there but on my mac it is so I have not clue from where to get the CA cert for my docker on pi that will work – Ciasto piekarz Feb 05 '17 at 03:31
  • If you really want to `ssh` as the question originally states, you can follow the instructions at: https://www.ibm.com/blogs/bluemix/2015/11/docker-workaround-lack-of-network-connectivity-between-client-and-container/ – Nehal J Wani Feb 05 '17 at 06:40

8 Answers8

158

It could be your image does not have the binary /bin/bash installed (as suggested before), I had the same problem and I was able to enter into the container using /bin/sh

docker exec -ti cc55da85b915 /bin/sh

Another workaround could be execute directly the commands without get access to any shell.

docker exec -ti cc55da85b915 ls /etc
Esteban Collado
  • 1,840
  • 1
  • 14
  • 15
  • It worked for me! Also can you tell us what are the -ti args for? – Fernando Fradegrada Nov 13 '17 at 17:51
  • 5
    @FernandoFradegrada "-t" is for "tty", basically it tells to docker to allocate a terminal session to execute the command. "-i" is for interactive, the docker will keep listening from the standard input (keyboard) to let the user introduce more command. Here is the link to the official documentation: https://docs.docker.com/engine/reference/commandline/exec/#description – Esteban Collado Nov 14 '17 at 16:52
  • Worked like a charm! Thanks!! – Divs Jul 31 '18 at 09:22
  • I'd like to add that the same thing works for `kubectl` command when `bash` doesn't work. – Aida Feb 06 '19 at 18:20
21

The image you're using seems that it doesn't have the binary /bin/bash installed but it should have /bin/sh

Try:

docker exec -it cc55da85b915 sh
Alaeddine
  • 1,571
  • 2
  • 22
  • 46
3

You might need to specify the full path to bash, e.g.:

docker exec -it cc55da85b915 /bin/bash

or /usr/local/bin/bash, or wherever bash is located in that image.

Hope this helps!

Castaglia
  • 2,972
  • 5
  • 28
  • 49
3

You have many different ways to do that, you can attach using docker's attach command.

$ sudo docker attach cc55da85b915 #by ID

Or you can use docker exec command:

$ sudo docker exec -i -t cc55da85b915 /bin/bash

If /bin/bash fails, you can use /bin/sh that works in more containers:

$ sudo docker exec -i -t cc55da85b915 /bin/sh
Asier Gomez
  • 6,034
  • 18
  • 52
  • 105
2

if you are still looking for an answer. This worked for me on windows.

winpty docker exec -it <containerid> sh
Pradeep Sreeram
  • 368
  • 4
  • 19
1

For Alpine based image, docker exec -ti cc55da85b915 /bin/sh and docker exec -ti cc55da85b915 ls /etc worked. As suggested by 'Esteban Collado'.

However for other Linux versions I use, docker exec -ti cc55da85b915 bash

1

Try Below Command:

docker exec -it cc55da85b915 /bin/busybox sh

To list all the available commands use:

docker exec -it cc55da85b915 /bin/busybox --list
Amin Golmahalleh
  • 3,585
  • 2
  • 23
  • 36
Umar Murtaza
  • 61
  • 1
  • 8
0

This will also relevant for Kubernetes pods.

For example if you'll try to connect to a pod which doesn't contain the shell you specified:

kubectl exec -it some-busybox-pod bash

(busybox have sh on it not bash).

You'll end up with the same error:

OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec: \"bash\": executable file not found in $PATH": unknown
command terminated with exit code 126
Rot-man
  • 18,045
  • 12
  • 118
  • 124