How to install and run docker image?

how to install and run docker image

This is the 3rd post in Kubernetes series. We will learn the first step of using docker here. Before moving forward, you will need to install docker on your system. Please follow these links for installation according to your operating system –

Installing Docker on Windows

Installing Docker on MacOS (Intel Chip / Apple Chip)

Docker Installation for Linux (deb / rpm)

This will install Docker Desktop on your computer. There are other ways of installing docker too but we used Docker Desktop here. Why? because its easiest to install and has everything required to run docker environment on system.

If you don’t know what docker image is and how it works, then please follow this guide – Understanding Docker Image with Dockerfile.

Pull Image Command

The first step is to pull an image. This will download the image from repository like Docker Hub into your system. Here is the command –

docker pull <image>

For example, this is the command for pulling node image

docker pull node

You can find the pull command for different images on docker hub. Check out this screenshot –

docker pull node on docker hub
Docker Pull Node

What this command will do? It will fetch the image from docker hub and run Dockerfile. So, it will download all the dependencies required to run node in a container. This includes OS as well. But it all depends on whether you already have those layers downloaded from other software image. Docker keep the cache of previously downloaded layers.

In terminal, this will look something like this –

cmd - docker pull node

A few things to note over here –

Incomplete pull command

docker pull node is not a complete command. But it works. This is because we are pulling image from docker hub repository. So, what happen with other repositories? Well, we use complete command there. What is the complete pull image command? Here it is –

docker pull repository-address/image:version

If we do not specify version, then docker assume we want to pull the latest version. But if you want a specific version, you can put that here –

docker pull node:14.20

If you need to pull image from any other repository (apart from docker hub) then use them like this –

docker pull

Here we are pulling my-image from AWS docker repository which is known as ECR. This is a private repository so an authentication is required by AWS (we will look at this in later tutorials). Here the repository address is This is a private address for my repository so it will be different for you. The focus here is that we need to provide such address in the command otherwise we can’t pull my-image, unlike docker hub.

Using default tag: latest

In the above terminal image, the first line is using default tag: latest. It indicates that we are not specifying any version. Here version is called as tag. So, no tag means latest.

latest: Pulling from library/node

We told you that the path of image was incomplete in command. This worked because of docker hub. In this line, docker indicated that the actual path is library/node. In realty, it also includes docker domain address.

12 alphanumeric hash : Downloading

The next 8 lines are the dependencies of image. Docker referred the node image and found a dependency layer. It then check the Dockerfile of this dependency and found other dependency. This way it will check the whole hierarchy of dependencies and download them.

If you check the Dockerfile of node, you will find that it is dependent on buildpack-deps:bullseye. Which further depends on buildpack-deps:bullseye-scm. So, the hierarchy is something like this –

|_ buildpack-deps:bullseye
….|_ buildpack-deps:bullseye-scm
……..|_ buildpack-deps:bullseye-curl
…………|_ debian:bullseye
……………..|_ scratch

Scratch is the empty image which is used to give starting to the base containers like operating systems. Here debian uses it.

Finally, the image will complete the downloads and is ready to run.

cmd docker pull node completed

In this terminal image you can easily see the complete path of node image – So, your pull command, in case of docker hub, could be –

docker pull

Running Containers using docker run

After pulling an image successfully, we are ready to start container. Starting a container means to run the image in its containerized environment. So, we are going to start a node server. The command to run an image is –

docker run <image>

For node image, we can use –

docker run node
docker run node

But you will notice that you got no output here. This is because your node container is not running. Why? We explained it here – Why docker run command not running my container?

As discussed in the above article, you may run your container with this command –

docker run -idt node
docker run -idt node

This hash code proves that the container is running now.