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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With