Ciasto piekarz
Ciasto piekarz

Reputation: 8277

How to ssh to docker container

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

I am trying to ssh to docker container, but it is giving this 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 it the right way?

Upvotes: 64

Views: 76549

Answers (8)

Umar Murtaza
Umar Murtaza

Reputation: 71

Try Below Command:

docker exec -it cc55da85b915 /bin/busybox sh

To list all the available commands use:

docker exec -it cc55da85b915 /bin/busybox --list

Upvotes: 2

Rotem jackoby
Rotem jackoby

Reputation: 22068

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

Upvotes: 0

Pradeep Sreeram
Pradeep Sreeram

Reputation: 388

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

winpty docker exec -it <containerid> sh

Upvotes: 2

super-coder
super-coder

Reputation: 31

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

Upvotes: 1

Alaeddine
Alaeddine

Reputation: 1677

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

Upvotes: 23

Asier Gomez
Asier Gomez

Reputation: 6558

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

Upvotes: 3

Esteban Collado
Esteban Collado

Reputation: 1910

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

Upvotes: 165

Castaglia
Castaglia

Reputation: 3089

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!

Upvotes: 3

Related Questions