Docker Part 3: How Docker Client works?

In the last 2 posts, we looked at what is Docker and why it is needed. In this post, we will try to install docker and see how the docker client works.

To install Docker, download it from the below link as per your OS and install using the installer command 

Docker Download Link

Once installation is done, execute the “docker” command on your terminal or command prompt to see if it got installed correctly or not.

If it got installed correctly then you will see the following output on the terminal:



As we are going to use our terminal to write docker commands, we need to log in to Docker Hub from our terminal. Use the below command to log in to Docker Hub from the terminal: docker login” 

It will then ask you about your username and password, enter those to log in. 



You should be able to see Login succeeded message on the terminal.

To check the docker version run “docker version” command 
 



Execute the below command to understand how docker actually works “docker run hello-world” 
The output of the above command will look like this:




In the above screenshot, you will see the “Hello from Docker!” message and below that the series of steps it took to get that output. 

It actually explains the steps that the Docker client takes to get an image from Docker Hub.

As soon as we type this “docker run hello-world” command on our terminal, our Docker Client or Docker CLI starts up and tries to communicate with Docker-Server

“docker run hello-world” command stats that we want to start a new container with the “hello-world” image. This hello-world image has a program running inside it that will just print the message that you see on the screen currently. 

Once the command reaches to the Docker-Server, it checks locally if that hello-world image is available in the local ImageCache or not. As we have just now installed Docker the ImageCache is empty. So as part of the next step, Docker Server reached out to Docker Hub to download that image. 

The message on the first line is "Unable to find image ‘hello-world: latest’ locally." 

Once the image is downloaded from Docker Hub then it will be stored in ImageCahe for future reuse. 

Then the Docker-Server takes that single image file of hello-world downloaded from Docker Hub, loads it in memory creates a container out of it, and then runs a single program in it which prints “Hello from Docker!” message on the terminal. 

So if we run the same command a second time, we will not see the message "Unable to find image ‘hello-world: latest’ locally." 


That’s it for this post. 

Signing off
Amit Raghuvanshi

Happy Learning :)

Comments

Popular posts from this blog

How does Amazon S3 stores data internally

Demystifying AWS S3 Batch Operations: A Step-by-Step Guide

HttpClient Part 2: Understanding HttpClientFactory in the .NET World