Docker Perquisite understanding & Setup
This is continuation of my previous article. if you haven't read that already, I recommend reading that first : https://www.dhirubhai.net/pulse/docker-containers-images-danish-javed-putsf/
Alright, we now have the basic understanding of what docker does, what are images and container. Now is the right time for us to start with our local setup.
In this article we'll learn
Docker Requirements
The only major requirement is Linux Kernal. Other than that it can work on even systems with not so great resources.
But why just Linux Kernal
Docker uses Linux Specific features like cgroup and namespaces for the containerization operations.
Okay, but why don't we have a windows and mac distribution
Ofcourse, it would be possible for the developer to create windows and mac just like we have multiple distribution for java, node python etc.
But would it really be that helpful ?
The answer is probably a big NO. Most of the servers running today, almost 96%, run on Linux. In the end, on the production, docker has to run in Linux. So it doesn't make much sense put that much effort to create another distributions. Creating and maintaining those many distribution would be very difficult while not being worth it at all.
So how do we run this on a Windows or Mac device ?
Simple answer : VM.
In this article, we'll be running docker on a Windows device (coz that's what I have, don't you dare call me poor). We'll use Windows native solution - WSL.
If you have a mac, you can still read this to have a basic understanding. But you won't be able to follow along this section. Please setup HyperKit separately.
What is VM ?
VM - Virtual Machine
We are used to see computers as a bunch of hardware and software combined together. When we, usually, think of computers we think 14th gen i9 processor, a DDR5 32/64 GB Ram, a TB or two NVMe SSD, RTX 5090 GPU, 4k 240Hz display, 4zone per key RGB, thermals etc. And ofcourse windows 11 as OS.
If you own a mac, I think you think, in a slight different manner. A macbook air or macbook pro etc. (Don't worry, mac users are not reading this, they went to setup hyperkit)
But you get the basic idea.
Virtual Machines are called so because, unlike the usual computers, they don't have a dedicated hardware. They are setup on any existing machine(referred as - host machines) and can utilize the same set of hardware.
We can setup a VM in our laptop and that is running windows, and the VM would use our existing resources, the same RAM, SSD, keyboard etc.
领英推荐
Why do we need a VM ?
To make better use of our resources.
We do have a windows laptop already. But docker needs Linux kernel. What do we do ? Buy a new laptop or wipe out windows from our machine and setup linux or setup a dual boot option. None seems nice. Buying a new laptop would be expensive. We can't let go of our Windows or Mac OS. Daily tasks would get hampered. Dual boot would be very resource extensive, slow down our systems overall and be an overkill for docker.
VMs provide an option to run multiple environment in the same device. Where one serves as host and the other is virtual. So we can keep using our windows or mac and yet have the option to bring in Linux as required.
It's like having the best of both worlds.
But if you're a complete nerd running Linux already, I don't think I have to explain you anything and you don't to setup a VM for docker.
Setup our VM
Enough of the chit chat, let's get to action.
We'll be using windows native solution to run Linux - WSL. It'll be version 2, often referred as WSL2.
That's literally it ????. We now have a linux VM running in our laptop
But, what exactly is WSL ?
WSL - Windows Subsytem for Linux
Its a windows feature that allows us to run Linux applications on windows. In our case, docker.
How does it work ?
WSL has HyperV, this is responsible for hosting VMs. Now that we have our VM running, that actually resides inside HyperV in WSL. The commands that we'll run inside this VM will run on the Linux Kernel which will directly interact with the hardware bypassing windows OS and kernal.
So with WSL and HyperV, the Linux kernal can directly interact with our hardware resources.
Okay, but how is WSL different from other VMs, like VirtualBox ?
In the next article, we'll run our first prebuilt hello-world app and hopefully run our own tiny little webapp in a container. Until then, keep learning.
Since I get time to draft these only on the weekends, you can checkout my notes at technotes.devdanish.in/docker