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 –
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 –
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 –
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 831022063645.dkr.ecr.us-east-1.amazonaws.com/my-project/my-image:v1.0.59
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
831022063645.dkr.ecr.us-east-1.amazonaws.com. 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.
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.
In this terminal image you can easily see the complete path of node image – docker.io/library/node:latest. So, your pull command, in case of docker hub, could be –
docker pull docker.io/library/node:latest
Running Containers using
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
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
This hash code proves that the container is running now.
- Introduction to Kubernetes
- Introduction to Docker, Containers, Images & Repository
- Install and Run Docker Images
- Docker Image – FROM, RUN, COPY, ENTRYPOINT, CMD, EXPOSE explained
- Why docker run or start command not running my container?
- How to list all docker images in system?
- How to list all docker containers?
- How to start/stop a docker container?
- Difference between docker run and docker start
- How to bind docker container port with host?
- How to get logs of docker container?
- How to live stream logs of docker container?
- Set custom name to a docker container
- Access docker container filesystem & terminal
- Getting docker details using docker inspect
- Kyverno – Installation, Policies, Testing, Reporting, Monitoring, Security
- Complete Kubernetes Project Step By Step
- Introduction to Kubernetes Objects