Do `docker container rm` and `docker container kill` effectively achieve the same

docker

From manpages:

docker container rm will remove one or more containers from the host
node. The container name or ID can be used. This does not remove
images.

docker container kill: The main process inside each container
specified will be sent SIGKILL, or any signal specified with option
–signal.

Is a container a running instance of an image?
So do docker container rm and docker container kill effectively achieve the same: the container will stop existing?

What are their differences?

What is "the main process inside a container"?

Is a container run exactly as a process in the host machine?

Thanks.

Best Answer

If you run a container..

eg

docker run alpine echo hello

It looks like it cleans up afterwards...

% docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

But it doesn't it's still there.

% docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
3a4772c0f165        alpine              "echo hello"        22 seconds ago      Exited (0) 20 seconds ago                       relaxed_ramanujan

This can be cleaned up with the rm command

% docker container rm 3a4772c0f165 
3a4772c0f165

% docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

So:

  • docker kill will kill a container.
  • docker rm will clean up a terminated container.

They are different things.

Note: you can tell containers to auto-clean:

% docker run --rm alpine echo hello
hello

% docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

Then you don't need to manually rm.

Related Question