Introduction
This is another article containing topic about docker. The topic is about removing docker images in the local machine. In order to remove images in the local machine, there is a specific command to achieve it. The command execution is in the command line along with the name of the image. The following is the pattern for removing the image :
docker rmi image_name
Before removing the docker image, first of all search the docker image. Searching the docker image is very simple. For further reference please read this link. It is actually a link for an article with the title ‘How to Show Available Docker Images in the Local Machine’. Just list the available docker image first. Execute the following command for listing the available docker images in the local machine :
docker images
The above command pattern execution is in the following output for giving an example about how to list the available docker images in the local machine :
root@hostname# docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos-nginx_web latest 36c49ff2d3bc 2 days ago 457MB apache_image latest 2051d26d51fa 2 days ago 1.61GB mariadb latest 7aca88b09cc5 5 days ago 356MB wordpress latest 42a9bf5a6127 5 days ago 502MB busybox latest 19485c79a9bb 13 days ago 1.22MB php apache aa4bdc74350b 2 weeks ago 414MB php 7.1-apache 1b3f4ce0de58 3 weeks ago 405MB centos 7 67fa590cfc1c 4 weeks ago 202MB centos latest 67fa590cfc1c 4 weeks ago 202MB ubuntu latest a2a15febcdf3 4 weeks ago 64.2MB tomcat latest 6e30b06a90d3 4 weeks ago 506MB mysql 5.7 e1e1680ac726 5 weeks ago 373MB mysql latest 62a9f311b99c 5 weeks ago 445MBy mysql/mysql-cluster latest 67fd04af4b8e 8 weeks ago 338MB mysql/mysql-server 5.7 d1469951af27 8 weeks ago 262MB tensorflow/tensorflow latest 7f03c4ff368a 2 months ago 1.17GB centos 9f38484d220f 6 months ago 202MB registry 2 f32a97de94e1 6 months ago 25.8MB hello-world latest fce289e99eb9 8 months ago 1.84kB apache-php5 latest 6bb5b2e462f9 17 months ago 479MB root@hostname ~#
Removing Docker Image
After retrieving the list of the available images above, just remove the intended image according to the output. For an example, in this article, remove the docker image with the name of ‘apache-php5’. Just execute the following command pattern to remove the docker image :
docker rmi image_name
Using the above command pattern above, try to remove one docker image as follows :
root@hostname ~# docker rmi apache-php5 Untagged: nimmis/apache-php5:latest Untagged: nimmis/apache-php5@sha256:712d35d5cc30e6a911e260e871f08f77d5684edcc50cba21163535714c547ff5 Deleted: sha256:6bb5b2e462f9516738d0ffefa3968435e5a743b3bc1cd7214179ae86f0a3e7c4 Deleted: sha256:9c087fd03fb892dcbcaaaf4b027bfc9bce9eb79f568b10868d0ce3986f5a1242 Deleted: sha256:266e8250f15cc4697124375c7c2f4182f12fc025aa1f98a4ddc0343633800e71 Deleted: sha256:9e3099547aa3006fb2805a9f61d1bd80e34448d7666c03b70c2b09dbda73ee77 Deleted: sha256:4decd5c92a42eee38202f724e81556b059095d95c9e510517f059f4bd04e7346 Deleted: sha256:b0a537e5d6c092f7c4cd3d088eb0402d32b6851baa834f9b9ef40610bb9aa2cd Deleted: sha256:a617bd7a310b090a2009887c88f91f1cd0e3c62024f05de9d080974da8cd303f Deleted: sha256:3764e41990df0e1d74002f6e5c9216b3db80cef7cca581b215ec8d976762b0eb Deleted: sha256:20724bef2f46162aab34c318c5de84580d2b010244d53228e5cb18b3ee545fd1 Deleted: sha256:f163978d2447e776307caaba226b83d07c8af497d9b3e59778ba6ddb663a7e8d Deleted: sha256:187107f7c00ed031ec24864d2c3166b8b88cfa237ca2cc93bef921327b8332b9 root@hostname ~#
After successfully removing the intended docker image, don’t forget to list the available docker images in the local machine again by typing the following command :
root@hostname# docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos-nginx_web latest 36c49ff2d3bc 2 days ago 457MB apache_image latest 2051d26d51fa 2 days ago 1.61GB mariadb latest 7aca88b09cc5 5 days ago 356MB wordpress latest 42a9bf5a6127 5 days ago 502MB busybox latest 19485c79a9bb 13 days ago 1.22MB php apache aa4bdc74350b 2 weeks ago 414MB php 7.1-apache 1b3f4ce0de58 3 weeks ago 405MB centos 7 67fa590cfc1c 4 weeks ago 202MB centos latest 67fa590cfc1c 4 weeks ago 202MB ubuntu latest a2a15febcdf3 4 weeks ago 64.2MB tomcat latest 6e30b06a90d3 4 weeks ago 506MB mysql 5.7 e1e1680ac726 5 weeks ago 373MB mysql latest 62a9f311b99c 5 weeks ago 445MBy mysql/mysql-cluster latest 67fd04af4b8e 8 weeks ago 338MB mysql/mysql-server 5.7 d1469951af27 8 weeks ago 262MB tensorflow/tensorflow latest 7f03c4ff368a 2 months ago 1.17GB centos 9f38484d220f 6 months ago 202MB registry 2 f32a97de94e1 6 months ago 25.8MB hello-world latest fce289e99eb9 8 months ago 1.84kB root@hostname ~#
As in the output above, the docker image with the name of ‘apache-php5’ is not exist anymore. In other words, the command execution for removing the docker image with the name of ‘apache-php5’ is a success. Another command which is also suitable to list or to search a specific docker image with a certain name is also available as follows :
root@hostname ~# docker image | grep apache-php5 root@hostname ~#
The output of the above command execution will result on nothing to display. It is because the docker image with the name ‘apache-php5’ is no longer exist in the local machine.