This is for Docker Newbies who just got docker installed and don’t know what to do with it or want to understand how it works in a fun way.
So you have successfully installed Docker on your machine and you are ready to start exploring the Docker world
HELLO-WORLD program is the first thing you code when you’re learning a new thing right? Well, it’s the same for docker.
You will get a sneak peek at how docker works, and don’t worry if you don’t know what a container or an image is.
docker run hello-world:
Open up your terminal and type:
docker run hello-world
Your command line should look like this and there you go, you just made your Hello-world in Docker, you officially made your first step into Docker.
Right under the Hello World message on your terminal, you can see the steps that docker took under the hood to get you the message on your terminal:
LET’S UNDERSTAND THESE STEPS:
So you executed the command “docker run hello-world”. That starts up that docker client or so-called docker CLI.
The docker CLI is in charge of taking commands from you and doing a little bit of processing on them and then communicating the commands over to something called the Docker Server who is really in charge of the heavy lifting.
When you ran “docker run hello-world”, that meant that you wanted to start up a new container using the image with the name of hello-world.
The hello-world image has a tiny little program inside of it whose sole purpose is to print out the message that you see in the terminal.
Now when you ran that command and it was issued over to the docker server a series of actions very quickly occurred in the background.
The first thing that the docker server did was check to see if it already had a local copy on your personal machine of the hello-world image or hello world file.
So the docker server looked into something called the image cache.
Now because you just installed docker on our personal computer that image cache is currently empty.
And that can be seen in the first line on your terminal:
So because the image cache was empty the docker server decided to reach out to a free service called docker hub to download the hello-world image.
The docker hub is a repository of free public images that you can freely download and run on your computer
Now the hello-world image is downloaded on your machine and stored in the image cache where it can now be rerun at some point in the future very quickly without having to redownload it from the docker hub.
After that the docker server then said OK great I’ve got this image and now it’s time to use it to create an instance of a container then essentially took that single file load it up into memory created a container out of it and then ran a single program inside of it and that single program’s purpose was to print out the message that you see in the terminal.
Now one thing that you’ll notice that’s kind of interesting if we run the docker run hello-world command a second time.
You’ll notice that you are not going to see the message of downloading or image not found locally again.
So the big lesson here is that the first time that you try to make use of any of these public images, you’re going to have to do a little bit of a download.
But in the future, you can start up a container using that image much more quickly because the image has already been downloaded to your computer.
Connect with me on Linkedin for more interesting tech stuff!
Thank you very much for your attention.