Docker Images

In Docker, everything is based on Images. An image is a combination of a file system and parameters. Let’s take an example of the following command in Docker.

➜  ~ docker run hello-world 
  • The Docker command is specific and tells the Docker program on the Operating System that something needs to be done.

  • The run command is used to mention that we want to create an instance of an image, which is then called a container.

  • Finally, "hello-world" represents the image from which the container is made.

Now let’s look at how we can use the Ubuntu image available in Docker Hub to run Ubuntu on our Ubuntu machine. We can do this by executing the following command on our Ubuntu machine −

➜  ~ sudo docker run -it ubuntu /bin/bash

Note the following points about the above sudo command −

  • We are using the sudo command to ensure that it runs with root access.

  • Here, Ubuntu is the name of the image we want to download from Docker Hub and install on our Ubuntu machine.

  • ─it is used to mention that we want to run in interactive mode.

  • /bin/bash is used to run the bash shell once Ubuntu is up and running.

Displaying Docker Images

To see the list of Docker images on the system, you can issue the following command.

➜  ~ sudo docker images 
REPOSITORY                                     TAG       IMAGE ID       CREATED        SIZE
opensecurity/mobile-security-framework-mobsf   latest    7a567d84d242   29 hours ago   2.2GB
ubuntu                                         latest    2b4cba85892a   40 hours ago   72.8MB
  • TAG − This is used to logically tag images.

  • Image ID − This is used to uniquely identify the image.

  • Created − The number of days since the image was created.

  • Virtual Size − The size of the image.

Removing Docker Images

The Docker images on the system can be removed via the docker rmi command.

➜  ~ sudo docker rmi 2b4cba85892a
...

Docker inspect

This command is used see the details of an image or container.

➜  ~ sudo docker inspect ubuntu 
[
    {
        "Id": "sha256:",
        "RepoTags": [
            "ubuntu:latest"
        ],
        "RepoDigests": [
            "ubuntu@sha256:"
        ],
        "Parent": "",
        "Comment": "",
        "Created": "2022-03-03T20:19:33.779048748Z",
        "Container": "",
        "ContainerConfig": {
            "Hostname": "b32714f341a6",
            "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 [\"bash\"]"
            ],
            "Image": "sha256:",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {}
        },
        "DockerVersion": "20.10.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": [
                "bash"
            ],
            "Image": "sha256:",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": null
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 72759661,
        "VirtualSize": 72759661,
        "GraphDriver": {
            "Data": {
                "MergedDir": "/var/lib/docker/overlay2/01fad90e654398c4edb07ceeb8f64a34b2428e0fd4cedd9b41f25782f0ea8675/merged",
                "UpperDir": "/var/lib/docker/overlay2/01fad90e654398c4edb07ceeb8f64a34b2428e0fd4cedd9b41f25782f0ea8675/diff",
                "WorkDir": "/var/lib/docker/overlay2/01fad90e654398c4edb07ceeb8f64a34b2428e0fd4cedd9b41f25782f0ea8675/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:"
            ]
        },
        "Metadata": {
            "LastTagTime": "0001-01-01T00:00:00Z"
        }
    }
]

Last updated