Of course, you’ll have to stop any running containers associated with the images. docker rmi image_id_1 image_id_2 image_id_3 You just have to specify the image IDs or the image names. You can also remove multiple docker images in one single command. If you want to remove all the containers associated with an image, just run this command: docker ps -a -q -filter ancestor=ubuntu | xargs docker rmĪnd now you can remove the docker image using the command shown earlier in this tutorial. You can use the magic of pipe and xargs to stop all the containers associated with an image: docker ps -a -q -filter ancestor=ubuntu | xargs docker stopĪnd then you can either remove the stopped containers or force remove the image (as you saw in the previous section). You may use the container IDs one by one but that will be too time-consuming. -q option only displays the container ID.Īnd then you need to stop all of them.
:~$ docker imagesĭebian latest 67e34c1c9477 2 weeks ago 114MB You need this image name (under repository column) or the Image ID to delete a docker image from your system. The output will show all the docker images and their image ID. Ways to remove docker imagesįirst, check the docker images present on your system with this command: docker images In this article, I’ll discuss various scenarios of deleting docker images from your system.
Deleting old and unused docker images will free up plenty of disk space for you. If you keep on creating docker images, you’ll soon start to run out of space.