DOCKER (What are Docker Images and How to run Docker Image)

Kasun Dissanayake
5 min readMar 8, 2020

This tutorial is on Docker Images and I am going to go very basic by step by step. In this tutorial, we are going to learn

  • What are Docker Images
  • How to pull Images
  • How to run a container using an Image
  • Basic Commands

Let’s get started…

I am using the Linux command line to do this tutorial. You can use your Windows command, Windows PowerShell prompt or Mac terminal.

$ docker -v

Use this command to check the Docker version and docker is installed.

$ docker images

Use this command to check whether there are any Docker images in your machine. This command will list all images in your system.

Currently, I am not having any docker images in my machine.

Now let us try to pull an image. First, create an account on Docker Hub and search for a particular image from the search bar on the top of the site.

I am going to pull Ubuntu Image. And you will find the pull command.

To pull this image use this command

$ docker pull ubuntu

It will get the latest tag by default if we do not use any tag.

Now if you run the command $ docker images you can see the pulled image.

What ate Docker Images?

Docker Images are templates used to create Docker containers. And basically these are files that have information about what all things be required to create a container. The container is a running instance of an Image. So when you run an Image the container is created. And Images are stored in registries. For example Docker Hub (Docker Hub is a kind of a Registry where other data images are stored)

Now as we have pulled the Ubuntu image if we want to provide any tag we can give it too. You can get information about tags in the DockerHub tags section.

$ docker pull <image name:tag>

Then the particular tag will be pulled.

Now let us go to some of the basic commands that you can use with images.

$ docker images -q

This command will show all the image IDs.

$docker images -f "dangling=false"

This will filter and show your images. So the Dangling images are the images that are associated with a container (or running container). Here dangling=false gives the images which are not associated with a container.

A dangling image is one that is not tagged and is not referenced by any container.

Run Docker Image

To run an image we actually create a container out of Image. We can use this command to run an Image

$ docker run <image name>

Now use this command to check running containers.

$ docker ps -a 

So here we can see the container created from the Ubuntu image. Yeah, we have already created the Ubuntu container from the Image. But this is not yet running.

To run this container we have to run another command.

$ docker run --name <name of Container> -it <image name>bash

-it means interactive mood and so that we can start the shell. I can give a name to this container by using — name MyUbuntu1.

Now you can see we are now inside the container. Now you can see the running containers in the system.

Inspect the Image

$ docker inspect <image name/ID>

This will show all the details of this Image like ID, tags, hostname, domain name and other information. The image typically contains a union of layered filesystems stacked on top of each other. Using this command you can see all the layers also.

Remove Images

$ docker rmi <image name/ID>

This will remove the latest images. But you can use tag name with this command to remove specific Image.

$ docker rmi <image name/ID>:<tag name>

This will remove the Image related to a specific tag. But an image has already been used by a container you cannot delete the image. To delete that kind of image first you need to stop the container then you can delete the image.

Otherwise, you can delete the image in force manner. Use this command to delete the image in force.

$ docker rmi -f <image name/ID:tag name>

Summary

What are Docker Images?

Docker Images are templates used to create Docker containers. The container is a running instance of an Image. A single image can be used to create multiple containers.

Where are Images Stored?

Registries (e.g. Docker Hub). It can be stored locally or remotely.

Docker can build images automatically by reading the instructions from a Dockerfile.

Docker was created by Solomon Hykes. Initial release in 13th March 2013. Soloman HYkes started Docker in France as an internal project within dotCloud (A platform as a service company)

The software debuted to the public in Santa Clara at PyCon in 2013 . Docker was released as a open source in March 2013.

Docker library is written in the Go programming language

Well!. This is the end of this tutorial. Let's learn about Docker Containers and command from another tutorial.

Thank You!

--

--

Kasun Dissanayake

Senior Software Engineer at IFS R & D International || Former Software Engineer at Pearson Lanka || Former Associate Software Engineer at hSenid Mobile