Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove all stopped containers: "docker rm" requires at least 1 argument

Tags:

docker

I'm reading a book on docker. It is a couple of years old.

I'll cite:

If you want to get rid of all your stopped containers, you can use
the output of docker ps -aq -f status=exited , which gets the
IDs of all stopped containers. For example:
$ docker rm -v $(docker ps -aq -f status=exited)

When I run this, I get:

michael@michael-desktop:~$ sudo docker rm -v $(docker ps -aq -f status=exited)
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.30/containers/json?all=1&filters=%7B%22status%22%3A%7B%22exited%22%3Atrue%7D%7D: dial unix /var/run/docker.sock: connect: permission denied
"docker rm" requires at least 1 argument(s).
See 'docker rm --help'.

Usage:  docker rm [OPTIONS] CONTAINER [CONTAINER...]

Remove one or more containers

Could you help me understand what should I do to gain what is intended.

like image 430
Michael Avatar asked Jul 15 '17 18:07

Michael


People also ask

How remove all stopped containers in docker?

Use the docker container prune command to remove all stopped containers, or refer to the docker system prune command to remove unused containers in addition to other Docker resources, such as (unused) images and networks.

How do I remove old docker containers?

To remove one or more Docker containers, use the docker container rm command, followed by the IDs of the containers you want to remove. If you get an error message similar to the one shown below, it means that the container is running. You'll need to stop the container before removing it.

Does docker rm stop container?

docker rm -f The final option for stopping a running container is to use the --force or -f flag in conjunction with the docker rm command. Typically, docker rm is used to remove an already stopped container, but the use of the -f flag will cause it to first issue a SIGKILL.


2 Answers

In order to remove all our stopped containers, you can first run

$ docker ps -a

This gives you the list of running and stopped containers, from which you can select what are the containers that you wanted to get rid. But if you want to get rid of all stopped containers, then you need to use

$ docker container prune 

This removes all stopped containers by giving you the following messages.

Warning! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y
Deleted Containers:
your container id list will be printed.
like image 178
Sidd Thota Avatar answered Sep 20 '22 15:09

Sidd Thota


It could simply means that you have no container with a status 'exited'.

The commands becomes then:

sudo docker rm -v

The lack of any parameter would trigger the error message you see.

But today, this would be done with docker container prune anyway.

like image 35
VonC Avatar answered Sep 21 '22 15:09

VonC