si yan
si yan

Reputation: 365

How to delete container use containerd ctr?

I use sudo ctr container run ... to run a container. But there are something wrong with the process in my container. So I suppose that there is no task is running. I use sudo ctr task ls, it shows,

TASK         PID    STATUS
test    0      CREATED

Then I want to kill it with sudo ctr task kill test. However, it shows that

ctr: process not started: unknown

Then I use sudo ctr task delete test. It also shows errors,

ctr: task must be stopped before deletion: created: failed precondition

I don't know how to delete this container. Once I delete this container, it comes with ctr: task must be stopped before deletion: created: failed precondition. How can I delete this container?

Upvotes: 3

Views: 4699

Answers (2)

Roy kathurima
Roy kathurima

Reputation: 114

I had the same challenge. Turns out in containerd ctr, tasks and containers are different things. According to this blogpost, a container is a metadata object that resources are allocated and attached to while a task is a running process in the system.

So, to answer your question, you can simply remove/delete the container by:

ctr container delete test

You can substitute delete with either del, remove or rm. They all do the same thing. That should get rid of your error

Upvotes: 1

vincent
vincent

Reputation: 46

You can try this way.

ps aux | grep shim
sudo kill -9 <pid of your process>

Upvotes: 3

Related Questions