Docker: The Beginning

Sarthak
CodeX
Published in
5 min readOct 17, 2022

Yep, it’s happening, Docker, all you need is to fire up containers, and microservices and play with the most powerful tool out there. Have you heard about the ancient city of troy? If not, you should read about it, your mind is going to be destroyed just like troy but of course without any fatalities.

Let’s start with Docker. Wait! is that Marlin? No! it is the whale that ate him and why is it carrying a bunch of stuff on its back? Wait a minute is that depiction of Moby dick? No, it’s not. The whale is carrying containers, and that’s what docker is, a container spinning-up tool. Now, don’t ask me why the whale. I could ask you why the clown in McDonald’s and then we could go back and forth with all this.(P.S. If you don’t know marlin, google)

What is a container? Now to understand this we have to go back and understand what a virtual machine is. A virtual Machine is a system where all its parts and bolts of it are virtually initialized. What do I mean by this? In layman’s terms, it means it’s just a machine that exists just so that we can run multiple systems on one system without the hassle of double booting. So basically, I can run Linux on windows and vice versa. Any system could be run via this method. Some of the famous virtual machine tools are Hyper-V, VirtualBox, VMware, and many more. So now, containers? That is exactly like a virtual machine but with a twist. So, the base of a virtual machine is that we define the resources it will get initially and after starting up the machine you cannot increase or decrease those resources. Suppose, You wanted an Ubuntu VM and the hardware configuration of your base machine is 8GB RAM, Intel i5 7th Gen Processor 4 core, and integrated Graphics card, and you have 2 cores and 4GB RAM in your VM, but initially you wanted 4GB RAM, but now the work is minimal, you want 2GB RAM allocated, now you have to power off that machine and reallocate resources, this is a problem, if you are running a live service on that machine, we cannot always restart the device and reallocate the resources.

So, here the containers come to the rescue, we pre-allocate resources in traditional VMs, we don’t do that in containers, it just takes directly from the hardware as much as it requires and no more no less. The baseline of these containers is they can directly access the hardware whereas in traditional VMs we had to allocate resources first then the VM could use those resources. Docker is a set of the platform as a service (PAAS) model that uses O.S. level virtualization whereas VMware/VirtualBox uses hardware-level virtualization

So, now that we have cleared out what containers are let’s get to where docker comes into the picture. Docker runs these containers and creates a virtual space for them to run on your system. It creates network adapters and much more to make sure that your containers run without interruption. Now docker has one more part called docker-compose, let’s leave that for another time, don’t worry, I’ll tell you everything and anything to get you started in docker and play with the containers.

Docker Ecosystem contains the:

1. Docker Client

2. Docker Daemon/Server

3. Docker Hub

4. Docker Images

5. Docker compose

Now let us discuss these components in a little bit of detail.

Docker Daemon

1. Docker daemon runs on the host O.S.

2. It is responsible for running containers

3. Docker daemon can communicate with other daemons

Docker Client

We interact with docker via the docker client

1. The Docker client uses commands and REST API to communicate with the docker daemon

2. When a client runs any server commands on the docker client terminal, the client terminal sends these docker commands to the docker daemon.

Docker Images

Docker images are the read-only binary templates used to create docker containers. There are certain ways to create docker images.

1. Take an image from the docker hub

2. Create an image from the docker file

3. Create images from existing docker containers

Docker Hub

The Docker registry which manages and stores the docker images is known as the docker hub. There are 2 types of registries

1. Public Registry

2. Private Registry

The names themselves are sufficient to know what these registries represent.

Installation Of Docker

Docker being native to Linux I will be walking you through the installation process on Linux itself. Though You can run Docker on any O.S. you like.

All you got to do is this:

sudo apt-get updatesudo apt-get install docker docker-engine docker.io containerd runc

Now if you get errors in this command refer to this link:

Install Docker Engine on Ubuntu | Docker Documentation

So now docker is all set up, let’s dive right into it

Docker Commands

First, let’s go over some simple commands

To see docker images in your system

docker images

To find images from the docker hub

docker search <image name>

To download the image

docker pull <image name>

To run a container

docker run -it --name <container name> <image name> <entry-point>

Let’s discuss this command further by breaking it into parts

So docker run is pretty obvious we want to run the container, after this -it so here “-i” and “-t” are separate commands written together, “-i” stands for interactive, and “-t” stands for open the terminal then come “ — name” which states the name of the container and then image name. So, what is an entry point? The entry point is the file or binary from which the container will start. Suppose you wanted to start from bash so we would write /bin/bash, if you have your config file then you add it there

The full command will look something like this

docker run -it –name ilovedocker ubuntu /bin/bash

Try this, it is fun

To start a container

docker start <container-name> OR <container-ID(first 4 characters)>

To go inside a running container

docker attach <container-name> OR <container-ID(first 4 characters)>

To see all containers

docker ps -a

To see only running containers

docker ps

To stop a container

docker stop <container-name> OR <container-ID(first 4 characters)>

To delete a container

docker rm <container-name> OR <container-ID(first 4 characters)>

To delete an image

docker image rm <Image-name>

I think this would be sufficient for now. Try out these commands and play with them.

I’ll be back with the continuation of this blog soon.

Stay curious!

Thanks.

--

--