Tuesday 11 May 2021

Tinkering with containerd on Linux - "cannot delete a non stopped container"

 I'm getting to grips with containerd as an alternate container runtime, having spent much of the past 5 years tinkering with docker etc.

I'm using an IBM Cloud Virtual Server to do this work, which is running Ubuntu 18.04.5 LTS 

There are a number of command-line interface (CLI) tools that one can use with containerd including the one that comes alongside it - ctr

ctr help
NAME:
   ctr - 
        __
  _____/ /______
 / ___/ __/ ___/
/ /__/ /_/ /
\___/\__/_/
containerd CLI

Having pulled an image, validated as follows: -

ctr image list

REF                                               TYPE                                                 DIGEST                                                                  SIZE      PLATFORMS   LABELS 

us.icr.io/dave/ubuntu_x86:latest application/vnd.docker.distribution.manifest.v2+json sha256:7a76e38256731356de234124f1d1078134c3e0cf02082b376977d7b0131d4195 289.1 MiB linux/amd64 -     

I created/launched a container: -

ctr run --net-host -d --rm -t us.icr.io/dave/ubuntu_x86:latest k8s_control_plane

using the -d switch to run it in the background ( as a daemon ).

I could see the resulting process running: -

ps auxw | grep k8s_control_plane | grep -v grep

root      3643  0.0  0.1 111968  7140 ?        Sl   14:37   0:00 /usr/bin/containerd-shim-runc-v2 -namespace default -id k8s_control_plane -address /run/containerd/containerd.sock

Having finished my tinker, I tried to remove the container: -

ctr container del k8s_control_plane

ERRO[0000] failed to delete container "k8s_control_plane"  error="cannot delete a non stopped container: {running 0 0001-01-01 00:00:00 +0000 UTC}"
ctr: cannot delete a non stopped container: {running 0 0001-01-01 00:00:00 +0000 UTC}

Head scratching time .....

So I'm equating this to Docker ....

So I've done the equivalent of docker run and then tried to do docker rm without doing docker stop

But how do I stop a running container using ctr ?

Well, ctr has the concept of tasks: -

ctr task list

TASK                 PID     STATUS    
k8s_control_plane    3670    RUNNING

Therefore, I need to stop that task: -

ctr task kill k8s_control_plane

ctr task list

TASK                 PID     STATUS    
k8s_control_plane    3670    STOPPED

and then delete the container: -

ctr container del k8s_control_plane

and then validate: -

ctr container list

CONTAINER    IMAGE    RUNTIME    

ctr task list

TASK    PID    STATUS    

More to follow .....

No comments:

Visual Studio Code - Wow 🙀

Why did I not know that I can merely hit [cmd] [p]  to bring up a search box allowing me to search my project e.g. a repo cloned from GitHub...