/    /  Docker – Images

Docker Images

 

An image is a combination of a file system and parameters in Docker.

$ docker run hello-world 
  • Docker commands tell the Docker program what to do.
  • Run creates an instance of an image, which is called a container.
  • Lastly, “hello-world” represents the container’s image.

Let’s use the CentOS image available on Docker Hub to run CentOS on Ubuntu. Execute the following command on Ubuntu to do so.

$ sudo docker run -it centos /bin/bash

Here’s what you need to know about sudo

  • To ensure root access, we use the sudo command.
  • The centos image is what we want to download from Docker Hub and install on Ubuntu.
  • -it is used to say we want interactive mode.
  • /bin/bash runs the bash shell once CentOS is up and running.

Displaying Docker Images

The following command will show you the Docker images on your system.

$ docker images

You can use this command to see all your images.

Output

We’ll get the following result when we run the above command

di1

You can see in the above output that the server has an image called centos. It has the following attributes:

  • TAG − Use this to logically tag images.
  • Image ID − Uniquely identifies the image.
  • Created − Days since the image was created.
  • Virtual Size − Image size.

Downloading Docker Images

Using Docker pull, we’ll download images from Docker Hub.

Syntax

Use the following syntax to run a Docker image in a Docker container.

$ docker pull image 

Options

  • Image − The image used to run the container.

Example

$ sudo docker run centos

Running this command will download the centos image and run it as a container, if it’s not already there.

The CentOS Docker image should be visible when we run the Docker images command.

Removing Docker Images

Let’s look at the docker rmi command in more detail to see how to remove Docker images.

$ docker rmi -f

Docker images can be removed with this command.

Syntax

$ docker rmi -f imageID

Options

  • ImageID − The ID of the image you want to remove.

Return Value

You will receive the Image ID of the deleted image in the output.

Example

$ sudo docker rmi -f 5d0da3dc9764

Here, 5d0da3dc9764 is my Centos Image ID.

Output

We’ll get the following result when we run the above command −

d

Let’s see some more Docker commands.

$ docker images -q

You can use this command to get just the image IDs.

Syntax

$ docker images -q

Options

  • q − It tells Docker to only return Image IDs.

Return Value

It will only show the Image IDs of the Docker images.

Example

$ docker images -

Output

We’ll get the following result when we run the above command

du

docker inspect

You can use this command to see details about an image or container.

Syntax

$ docker inspect Repository 

Options

  • Repository − The image’s name.

Return Value

You’ll get detailed info on the image.

Example

$ sudo docker inspect centos

Output

Here’s what you’ll get from the above command:

di4