This article is originally written here with images attached -> https://easyontheweb.com/docker-for-absolute-beginners-what-is-docker/
So after procrastinating this for a long long time, I finally dove into the much hyped but untouched by me world of the Docker and it’s surrounding ecosystem a couple of days ago. Now, initially I’d thought of completing one project using Docker and Kubernetes and all before writing an article about it but then I decided to just jot down my first day experience getting to know it. After all, only then would it be Docker for Absolute Beginners right? When I give my views as an absolute beginner of the technology myself.
In this article I’ll touch upon what is docker, the docker ecosystem, containers and how to install Docker and run your first docker command on Mac.
But before all that the most important question to answer is this – Why Docker ?
Why Docker ?
Okay, so why to use Docker ? Well, Imagine a scenario – your friend has just completed his web application in Ruby On Rails and pushed the code onto his Github profile and asked you to clone the repo and check the application in your machine. You just go onto his profile, clone his repo onto your system and then run the command he asked you to run in order to start the project.
What will most likely happen? Well, you’ll get an error along the lines “Rails not installed” or something similar if Rails is not installed in your system. You then decide to install Rails on your system. When you try to do that, you get another error “Ruby not installed” and this just keeps on going deeper and deeper until you are frustrated with all the setup. (This is an imaginary scenario BTW, I’m not sure what errors will you get).
I’m sure if you’ve been in development for a while you surely have faced situations where setting up of applications and their dependencies has made you want to kill yourself. I know it has happened with me, many times.
To solve this issue is what Docker is for. Docker makes it really simple for you to install and run any piece of software without worrying about the dreaded dependencies. It’ll just make everything run. If your friend’s project was dockerized and you had docker on your system as well, running his application on your system would have been as simple as running it on his.
What is Docker ?
Docker actually is an ecosystem consisting of many parts like the Docker-CLI, Docker daemon, Docker hub, Docker compose etc. The main concept behind this ecosystem is to create and manage images and containers.
I know I know, the first thing that comes to mind is what are images and containers ?
Let us think of one thing first – what happens when you run a program on your computer? Well, the operating system sets aside a set of resources for that program and then those resources are utilised in running the program. If one of the required resources is not found that is required to run that particular program, then the system asks us to install that.
The operating system actually creates a space inside your machine where that program runs. Think of an image as that space, the image comes pre-filled with all the dependencies pre-installed for that particular program to run, all you need to do is click on that image and your program will run no matter what machine you are on.
Containers are just instances of this image. Think of it this way, you create a program called ABC which needs to packages called X and Y to run properly. What you would do with docker is create an image of your program that contains X and Y along as well. This image you can then send along anywhere and anyone with docker can simply create an instance of this image on their machine (the instance called a container) and run ABC.
The same image can create as many number of containers as you wish and all of them would run easily out of the box.
Installing docker for Mac
Installing docker on your Mac operating system is just as simple as any other application you install.
Go on this link -> https://www.docker.com/get-started and download docker for Mac. This will download a .dmg file of docker that you can click on and install. Then, just drag and drop docker into applications of your OS and you can then run Docker.
Click on the docker icon in applications. Even though it would seem like nothing happened, you will see a docker icon appear on the notification panel up top which would boot up in a minute and congratulations! Docker is successfully running on your system.
Using docker for the first time
First of all, let me tell you how to work with docker and what happens when you enter a command. So, working with docker involves writing terminal commands and issuing commands to the docker-cli . This docker cli (client) then asks the docker server and that is what actually executes your operation.
Let us see with the world famous hello-world example.
docker run hello-world
In the image above you see that I ran the first docker command with docker run hello-world.
The first thing it actually did was to ask the docker server (also in your own computer) to search for an image called hello-world in the computer. As it was unable to find the image locally it went out to the docker hub, searched for the image there and downloaded that image and ran it !
Think of the docker hub like the App Store for docker where there are many many images. Our command asked docker to find the image , either locally or in the hub and start a container as an instance of the image. What that means is that the OS created a separate namespace and resources for that program to execute and all of this was handled by Docker itself.
Pretty neat , eh ?
Even though this might not seem awfully helpful I would suggest you to use Docker once to install something a bit more complicated, like Redis. Then you will understand the true powers it has.
That is it from my side on this very first Docker article and I will keep posting further interesting articles on Docker and DevOps now that I’ve started diving into this field myself.
For other web dev posts that might interest you , check this out -> https://easyontheweb.com/blog/
Top comments (0)