Remove old Docker containers Code Example

Last Updated On Monday 4th Oct 2021
	docker container prune
	

Since Docker 1.13.x, you can use Docker container prune.

docker prune commands

	$ docker container prune
	
	$ docker system prune
	
  • When you run docker ps -a, you might have too many containers and want to remove old containers.
  • You can remove those containers as below.
	$ docker rm `docker ps -aq`
	

If the specified container is running, you’ll get an error.

	Failed to remove container (f6259edb8236): Error response from daemon: Conflict, You cannot remove a running container. Stop the container before attempting removal or use -f
	

remove all docker images

	docker rmi $(docker images -q)