Docker Image Remove

docker image rm command is used to remove one or more specified images.

In the below image we are deleting images named newubuntu using the rm command.

learning-ocean:~ gaurav$ docker image rm newubuntu
Untagged: newubuntu:latest
Deleted: sha256:f74a9dbd167eff2e712a463d7ddee9cb66226afc544d9862a8d371acd82d2d86
Deleted: sha256:5e4aa03dd2c2959645ad3bebb49e0feed5abc9fcb849b6d13c2028d05fce5db2
learning-ocean:~ gaurav$

We can also use -f flag to forcefully remove an image as shown in the image below.

docker image rm -f newubuntu

Similarly, the following command can also be used to remove the images.

docker rmi newubuntu

Docker Image Inspect

docker image inspect command is used to display detailed information for one or more images.

In the below, we will inspect the image named ubuntu and tag 14.04.

learning-ocean:~ gaurav$ docker image inspect ubuntu:14.04
[
    {
        "Id": "sha256:13b66b487594a1f2b75396013bc05d29d9f527852d96c5577cc4f187559875d0",
        "RepoTags": [
            "ubuntu:14.04"
        ],
        "RepoDigests": [
            "ubuntu@sha256:5c01e896fa6eeaa41f3509c64af668d71d06e318cfe373dabab9d61b9eaf6441"
        ],
        "Parent": "",
        "Comment": "",
        "Created": "2021-03-25T22:33:44.754436368Z",
        "Container": "a55677c29cfc1b4d4574b70df6fb6aa1db116fecd36b66d33ed480999a14037d",
        "ContainerConfig": {
            "Hostname": "a55677c29cfc",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "#(nop) ",
                "CMD [**/bin/bash**]"
            ],
            "Image": "sha256:8de4ecfd37404a523d0253873a2b15a274d3657e9f726b472eb82c32ffbc76f4",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {}
        },
        "DockerVersion": "19.03.12",
        "Author": "",
        "Config": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/bash"
            ],
            "Image": "sha256:8de4ecfd37404a523d0253873a2b15a274d3657e9f726b472eb82c32ffbc76f4",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": null
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 196513448,
        "VirtualSize": 196513448,
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/656324b424c4846a04700f4ca35ba836732f1b3e7eaf57ea0e7d58850c4f818e/diff:/var/lib/docker/overlay2/2715fed89f10846d3980684ef7d6d0248c9d1d58a6f7eda7fa8a3789d11bad00/diff",
                "MergedDir": "/var/lib/docker/overlay2/215d4933179c167f55efba5c796a9ed71440c9782a66b9e7ff45c446ca4d40be/merged",
                "UpperDir": "/var/lib/docker/overlay2/215d4933179c167f55efba5c796a9ed71440c9782a66b9e7ff45c446ca4d40be/diff",
                "WorkDir": "/var/lib/docker/overlay2/215d4933179c167f55efba5c796a9ed71440c9782a66b9e7ff45c446ca4d40be/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:f2fa9f4cf8fd0a521d40e34492b522cee3f35004047e617c75fadeb8bfd1e6b7",
                "sha256:30d3c4334a2379748937816c01f5c972a8291a5ccc958d6b33d735457a16196e",
                "sha256:83109fa660b2ed9307948505abd3c1f24c27c64009691067edb765bd3714b98d"
            ]
        },
        "Metadata": {
            "LastTagTime": "0001-01-01T00:00:00Z"
        }
    }
]

learning-ocean:~ gaurav$

We can see above that the detailed information about the image is listed in the json format.

Docker Image Prune

This command will delete all the unused images which are not referenced by a container from a machine.

Usage:

docker image prune [OPTIONS]

Options:

--all, -a Remove all unused images, not just dangling ones
--filter Provide filter values (e.g. until=<timestamp\>)
--force, -f Do not prompt for confirmation