Sign in
Log inSign up

Introduction to Docker

Deepak Tripathy's photo
Deepak Tripathy
·Mar 3, 2022·

6 min read

Introduction to Docker

BEFORE CONTAINERS

Let us dial back the clock. Back when computers were a novelty, and companies wanted to run their applications, they would have had to buy a server for doing so. However, this came with a caveat: you could only run one application per server. If you wanted to run multiple applications, you would have to buy as many servers. As costs would skyrocket, this was a problem, for both the company and the environment on a larger scale

IBM fixed this issue by introducing the concept of virtual machines into the game. With them, we could run multiple applications on the same server. You may have heard of / done dual booting on your PC; like installing windows on your Mac device or Ubuntu on Windows. These are virtual machines. However, they had a problem as well. They needed their own operating system, which tended to take up a lot of memory and storage on your hard disk. This made them slow and not so efficient.

In came containers.

WHAT IS A CONTAINER

Imagine you are moving to US from India. Would it make sense to send your belongings one by one, or would you rather put them all in one giant box and ship the box directly? Obviously the latter, right?

That big box is, in simple terms, a container.

Let’s say you built a website that works well on your system but your friend runs into some problems with it when they try using it on their computer. To avoid such hassles, you can use a container, which would ship the entire website along with its dependencies, such as the web database, front end, back end, source code, etc. This would ensure that the website runs smoothly.

In computing terms, containerization is an efficient method for running, deploying and scaling applications.

CONTAINER VS VIRTUAL MACHINES

CONT.png Any application which runs on a virtual machine will require a guest OS to run, which would require a hypervisor. A hypervisor manages the virtual machines and is used to create multiple machines on the host operating system. As you can see from the picture, every OS would require a dedicated amount of space in the hardware, which is virtually divided.

In the case of containers, you need have only one operating system, and on top of that, you have a container engine, on which you run applications. They use the idea of isolating your application from the main operating system.

To sum it up succinctly, virtual machines use multiple operating systems to run multiple applications whereas containers use only the host operating system to run applications via the container engine.

In reality, however, containers run on top of virtual machines. You can say they are a lightweight alternative.

WHAT IS DOCKER

Docker is one among many container platforms that allows you to build such containers to test, build and scale applications rapidly and easily by running them in isolated environments.

WHY USE DOCKER

• Helps transport code faster

• Makes scaling, deploying and identifying issues in the application easier

• Saves up space as you don’t need to install the whole application locally

DOCKER TERMINOLOGIES

Docker Runtime

It allows us to start and stop containers. There are two types:

(i) Low-level runtime (runc)

(ii) High-level runtime (containerd)

Docker Client

It is what we use to interact with Docker. You can think of it like the user interface for Docker. Whenever you type in a command, the client sends these to the daemon.

Docker CLI

It allows users to issue commands to the Docker Daemon. Docker uses a client – server architecture.

ARCH.png

Docker Engine

It is responsible for the overall functioning of Docker platform. It is a client-server based application with three components:

(i) Server – which runs the daemon

(ii) Rest API – deals with the interaction of applications with their server

(iii) Client – which is nothing but the command line interface (CLI)

Docker Daemon

It is the heart of the Docker architecture, which does the crucial work of building, running, and distributing the containers. It also manages the Docker images and the containers.

Docker Image

The file that contains the source code, operating system files to run the application along with its other dependencies inside the container is called Docker image. A containerized application is the running instance of an image. Docker images are immutable.

Dockerfile

It contains the list of instructions to create Docker images.

Docker Registries

This is where Docker images are stored. Docker hub is the official online public repository of Docker where you can find all the images of popular applications. Docker hub also allows us to create our own images for our application.

INSTALLING DOCKER

One last thing that we need to know before we go ahead and get some hands on with a few Docker commands is to have Docker installed.

You can refer the official documentation to get started.

If you want to skip installation, you can head to Play With Docker, an interactive online playground for Docker.

Getting started with Docker commands

Let’s look at some basic Docker commands to get our hands dirty.

docker run

image.png

This command first creates the container, and then it starts the container. Before creating the container, it will first check if the latest official image of hello-world is available on the Docker Host (the local machine on which the docker engine is running). If not, like in the case above, it will automatically download the same from Docker Hub before creating the container.

run keyword here means you are running an image to create the container, and hello-world is the image name.

docker images

This command lists out all the Docker images that are present in the Docker Host.

image.png

Let's decode each and every term used here:

(i) REPOSITORY - This shows the name of the docker image.

(ii) TAG - This basically represents the version of the image being used. Each image has its own unique tag.

(iii) IMAGE ID - a string consisting of alphanumeric characters which is associated with every image.

(iv) CREATED - This depicts when the image was created

(v) SIZE - This represents the size of the image

docker ps

Aliter: docker container ls

It allows us to view all the containers that are running in the Docker Host. image.png

docker inspect  [image_name]

It gives information on the image.

docker container prune -f

It will remove all the inactive (i.e. stopped) containers from Docker.

image.png

docker rmi [image_name]

It allows us to remove an image(s) from the Host.

image.png

To remove all the images at once, we rewrite the rmi command in the following manner:

docker rmi $(docker images -q)

image.png

Thank you so much for taking your valuable time for reading

Inspired by Kunal Kushwaha and his tutorials, I took the initiative to learn in public and share my work with others. I tried my level best in squeezing as much information as possible in the easiest manner. Hope you learnt something new today :)

Any feedback for further improvement will be highly appreciated!

Hassle-free blogging platform that developers and teams love.
  • Docs by Hashnode
    New
  • Blogs
  • AI Markdown Editor
  • GraphQL APIs
  • Open source Starter-kit

© Hashnode 2024 — LinearBytes Inc.

Privacy PolicyTermsCode of Conduct