Obsolete containers or images occupy space, you might want to clean up images or containers from the host to clean up space or to install and run new ones. Docker provides the following options for cleanup:
docker stop
:docker stop
can be used to stop a running container. A container cannot be removed unless it is in the stopped state. You can use the-f
or-force
option to force stop a container:
docker stop [container id/name] -f docker stop $(docker ps -a -q) # stops all the containers
docker rm
:docker rm
can be used to remove a stopped container.docker rm
can be concatenated with other listing commands for a consolidated operation as follows:
docker rm [container id/name] -force #removes container by id or name docker rm $(docker ps -a -q) #deletes all stopped containers
docker rmi
:docker rmi
can be used to remove an image from the container host using theimage id
,name
,tag
, ordigest
value. If an image has multiple tags all the tagged images...