Not able to exec into container

Viewed 2828

I am not able to exec into container which uses containerd as runtime.

I need to check some processes running inside the container. Is there any way to exec into container?

I am able to list containers using ctr cli.

Any help would be appreciated.

6 Answers

An alternative to the ctr command that K D Singh wrote about is crictl, so you can use it like so

crictl exec -it 9b47589560c6d /bin/sh

where 9b47589560c6d would be replaced by your container id (doesn't work with names as far as I know).

exec is a sub-command of command task,try

ctr -a $CONTAINERD_HOST -n $NAMESPACE t exec -t --exec-id $exec_id --fifo-dir /tmp $executor_id bash

Firstly run to learn container id:

sudo crictl ps -a

enter image description here

Be careful to use container id (first three letters enough):

sudo crictl exec -it 27e /bin/sh

enter image description here

With ctrctl, we can give seperate commands for images, container and pod (like rmi: remove image, rmp: remove pod, rm: remove container)

Commands: https://github.com/kubernetes-sigs/cri-tools/blob/master/docs/crictl.md

You can use exec command

docker exec -it <container name> /bin/sh

The -i option keeps the STDIN open and -t allocates a pseudo-tty

This will open the shell and you can execute any command inside the running container.

You can connect to the shell of a running container and pretty much do anything there.

docker run -i -t <IMAGE> /bin/sh

The -i option keeps the STDIN open and -t allocates a pseudo-tty

This will open the shell and you can execute any command inside the running container.

Related