Docker Image: Commands And Their Usage

If you haven’t, then I would suggest that you go through Introduction to Docker to have a better understanding of the basics of docker and images in general.

Now, let’s get started with some of the most used and important commands that you would need to use when working with images.


So if you want to build your own docker image, which at some point you would need to do, this is the command for you.

It is accompanied by many flags, as any important command would be. Let’s go through some them 1 by 1.

— build-arg

So you have a Dokerfile, a file used to create new images, and that file needs some arguments. You would then simply need to go

— file or -f

Well you must have understood it by having a glance at the above code snippet, it is used to tell the name of the Dockerfile while building an image


To understand this command, you’ll first need to understand what an intermediate container is.

So, whenever a Dockerfile is being executed and a new image is being made, docker uses a layered approach.

What this does is that, whenever a RUN, etc command is executed, the pre-existing image is now a container with a top level R/W image.

This R/W layer is then packed into others to form a read only set of layers forming an image.

Further instructions are run on this image, forming another layer and thus container, to be packed again to form an image.

This process leads to a set of intermediate image and intermediate containers created in the process.

When you want to delete these intermediate containers, you use this flag

--quiet or -q

Building an image is a noisy process that often has a lot of lines printed out on the terminal.

If you want to keep it neat and tidy and don’t want any output on the screen, use -q.

-- tag or -t

It must have happened that whenever you would have pulled an image, it states that no tag mentioned, and it pulls the image with the tag latest.

Well tags are used to simply tag the images to differentiate between different versions, environments, etc.


Docker images contain in them alot of information like

  • a list of all the layers
  • metadata
  • OS
  • Config details

and much more.

To get a list of all the details about an image, we simply use


is again a command that you’ll use a lot.

In general it is used to list all the images. By default this does not include intermediate images.

But then, it again comes with a lot of flags.

-a or --all

This flag is used when you want to see all the images, including the intermediate images

-- digests

digests flag is used to list all the images and add one more column to the output, the sha digest of the image


This command enables you to remove the dangling images. It often leads to a confirmation.

Dangling images are those images which are simply staying and occupying space without any specific purpose and you won’t regret removing them. (In most cases)

Although you can use -f or --force flag to specify that you don’t want to be prompted.


Now is the time to let you know about registry.

Registries are nothing but docker objects that store docker images. The most popular and commonly used is dockerhub.

So whenever you need to pull an image from a registry, you use the pull command.

By default it pulls the one with the latest tag, if not explicitly mentioned.

But if you want to download all the tagged images, you simply use -a or --all-tags flag


It’s just the opposite of pull and simply pushes the image to the registry.


Now that you know how to add images, you should also know how to remove them. It’s through rm command.

That are some of the most commonly used docker image commands that you will use.

DevOps | Creator | Learner

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store