Docker Concepts - What is docker? and other related entities.

Published on
11 mins read
––– views

Virtual Machines

It uses a hypervisors concepts to run on hardware basically on a host OS. Every VM has its own guest OS running on the host OS. Developing a application inside the VM is basically we need to install OS and setup environment.

Disadvantages

  1. Boot time is high.
  2. Performance, efficiency are not that great
  3. Deploying similar environment inside the VM is not easier.
  4. Snapshot of VM takes more space in Hard disk
  5. VM is 100% efficent in terms of development as it comes with more additional binaries.
Source: https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.researchgate.net%2Ffigure%2FHosted-Virtual-Machine-Architecture_fig2_242077512&psig=AOvVaw3j-Ro8MOfyltXYuSC_c0XN&ust=1671657571284000&source=images&cd=vfe&ved=0CBAQjhxqFwoTCJCmwO-PifwCFQAAAAAdAAAAABAE

Docker

Docker is an open platform for developing, shipping, and running applications.
Docker enables you to separate your applications from your infrastructure so you can deliver software quickly.
Docker provides the ability to package and run an application in a loosely isolated environment called a container.

Containers are lightweight and contain everything needed to run the application, so you do not need to rely on what is currently installed on the host.


All you need is to

  • Develop your application and its supporting components using containers.
  • The container becomes the unit for distributing and testing your application.
  • When you’re ready, deploy your application into your production environment, as a container or an orchestrated service like kubernettes .

The underlying technology🔗

Docker is written in the Go programming language and takes advantage of several features of the Linux kernel to deliver its functionality. Docker uses a technology called namespaces to provide the isolated workspace called the container. When you run a container, Docker creates a set of namespaces for that container.

These namespaces provide a layer of isolation. Each aspect of a container runs in a separate namespace and its access is limited to that namespace.

What can I use Docker for?

  • Fast, consistent delivery of your applications (Containers are great for continuous integration and continuous delivery (CI/CD) workflows.)
  • Responsive deployment and scaling
  • Running more workloads on the same hardware

Docker architecture

Docker’s features and tools

In Linux, the technology already existed to create containers and containerised apps. But it was a little esoteric and hard to understand.

Docker made it much easier for developers to understand and use container technology, by creating some useful features, like:

Some of the features of Docker include:

  • Docker Engine – a command line tool (docker) (client) which creates and runs containers on your computer. The Docker daemon (dockerd) listens for Docker API requests and manages Docker objects such as images, containers, networks, and volumes. A daemon can also communicate with other daemons to manage Docker services. When you use commands such as docker run, the client sends these commands to dockerd, which carries them out. The docker command uses the Docker API. The Docker client can communicate with more than one daemon.

  • The Docker container image format – for creating and sharing container images, which later became an open standard An image is a read-only template with instructions for creating a Docker container. Often, an image is based on another image, with some additional customization. You might create your own images or you might only use those created by others and published in a registry.

  • The Dockerfile – a language for building container images. Dockerfile with a simple syntax for defining the steps needed to create the image and run it. Each instruction in a Dockerfile creates a layer in the image. When you change the Dockerfile and rebuild the image, only those layers which have changed are rebuilt. This is part of what makes images so lightweight, small, and fast, when compared to other virtualization technologies.

  • Docker Registry – an online registry for publishing and sharing container images over the internet. A Docker registry stores Docker images. Docker Hub is a public registry that anyone can use, and Docker is configured to look for images on Docker Hub by default. You can even run your own private registry. When you use the docker pull or docker run commands, the required images are pulled from your configured registry. When you use the docker push command, your image is pushed to your configured registry.

  • Docker Compose – a lightweight way to share container setup instructions

  • Docker Swarm mode – a tool for managing containers running on multiple servers

Virtual Machine vs Docker

What is Container?

Simply put, a container is a sandboxed process on your machine that is isolated from all other processes on the host machine. That isolation leverages kernel namespaces and cgroups, features that have been in Linux for a long time. Docker has worked to make these capabilities approachable and easy to use

A container is a runnable instance of an image. You can create, start, stop, move, or delete a container using the Docker API or CLI. You can connect a container to one or more networks, attach storage to it, or even create a new image based on its current state.

By default, a container is relatively well isolated from other containers and its host machine. You can control how isolated a container’s network, storage, or other underlying subsystems are from other containers or from the host machine.

A container is defined by its image as well as any configuration options you provide to it when you create or start it. When a container is removed, any changes to its state that are not stored in persistent storage disappear.

Example docker run command

The following command runs an ubuntu container, attaches interactively to your local command-line session, and runs /bin/bash.

$ docker run -i -t ubuntu /bin/bash

When you run this command, the following happens (assuming you are using the default registry configuration):

  1. If you do not have the ubuntu image locally, Docker pulls it from your configured registry, as though you had run docker pull ubuntu manually.

  2. Docker creates a new container, as though you had run a docker container create command manually.

  3. Docker allocates a read-write filesystem to the container, as its final layer. This allows a running container to create or modify files and directories in its local filesystem.

  4. Docker creates a network interface to connect the container to the default network, since you did not specify any networking options. This includes assigning an IP address to the container. By default, containers can connect to external networks using the host machine’s network connection.

  5. Docker starts the container and executes /bin/bash. Because the container is running interactively and attached to your terminal (due to the -i and -t flags), you can provide input using your keyboard while the output is logged to your terminal.

  6. When you type exit to terminate the /bin/bash command, the container stops but is not removed. You can start it again or remove it.

What can you do with Docker?

There are lots of things that you can do with Docker:

  • Create container images (also called Docker images) for your applications - with docker build and a Dockerfile

Using Docker to create and publish container images

Using Docker to create and publish container images

Source: Tutorial Works

  • Run your own container images using Docker Engine (Dockerfile)

  • Share images with coworkers or other teams, by pushing them to a private image registry

  • Share images on the internet by pushing them to Docker Hub (a public image registry)

  • Run third-party containers such as databases, using images pulled from Docker Hub

  • Run multi-container applications with Docker Compose (docker-compose.yml)

Along with these useful developer features, there’s also Docker Swarm mode, which is a utility for managing a cluster of Docker instances. Swarm lets you manage containers running on many different servers.

What is Kubernetes?

If docker run is the way to run containers on your laptop, then Kubernetes is like a robot that runs docker run on dozens, or hundreds, of servers. Kubernetes turns a set of servers into a complete, private cloud.

Kubernetes is server-side software for managing containers.

t automates all of the time-consuming tasks like creating containers and placing them on servers, configuring containers, checking container health, and managing access to resources like memory and CPU. This puts it in a category of software called container orchestration tools.

Kubernetes hides away the details of your servers, and instead provides you with a standard API to deploy software onto the cluster. As a developer or sysadmin, you don’t deploy your container-based app to a specific ‘server’, you give Kubernetes some instructions, and it decides where to pull the container image and start the container.

Kubernetes features and tools

Kubernetes provides a set of “primitives”. These primitives are like building blocks for creating apps, in the same way as you might build a model from standard Lego bricks. These are the terms you might have heard of, like Pods, Services and Deployments.

Kubernetes comes with these features:

  • Container scheduling – intelligently figuring out where to place containers, based on how busy each server is.

  • Container management – starting, stopping and restarting containers.

  • Auto-scaling containers – starting more containers when needed. For example: if an app is suddenly experiencing high traffic (e.g. on Black Friday), Kubernetes can start more containers to handle the load. It can also stop those containers afterwards, so you’re not using resources which you don’t need.

  • Networking – Creating and managing networks to allow containers to communicate with each other, and to load balance traffic across several instances of your app. (You could do this yourself, but when you’re running 1,000s of containers it gets real tough)

  • Storage – managing access to disk, for containers which need to write files

  • Logs and monitoring – making it easier to gather logs from containers and monitor containers’ health

  • Security – establishing common rules and enforcing security restrictions on containers

Plus, Kubernetes is very extensible. You can change the way the networking layer works… you can connect your Kubernetes cluster to your cloud account so it can request more resources if needed… you can even use Kubernetes to manage virtual machines as well as containers (using the KubeVirt project).

Things you can do with Kubernetes

Once you’ve got a Kubernetes cluster up and running, what do you actually do with it? Why do people use Kubernetes?

  • Deploy your own container-based applications

  • Deploy third-party container-based applications, like databases or web applications

  • Connect your apps to each other – e.g. so that your back-end API can talk to the database, or connect many containers together into an architecture of microservices

  • Upgrade applications by stopping existing containers and starting new ones with the updated software

  • Gather metrics on your apps – e.g. memory usage, CPU usage, and so on.

Kubernetes is popular because it standardised all of this stuff. We’ve been doing things like networking and log management for a long time, but now there is a standard way to implement these requirements (which pretty much every company has).

Cloud Infrastructure

Cloud infrastructure consists of all hardware and software components that are needed to support the delivery of cloud services to the customer.

The main physical components of cloud infrastructure are

  1. networking - software-defined networking (SDN) software to manage cloud connections
  2. servers - Compute - Performs the basic computing for the cloud systems. cloud service providers offer servers where organizations can store data, run applications or carry out analysis of various business processes.
  3. data storage - a combination hard disks and flash storage designed to move data back and forth between the public and private clouds.
  4. virtualization - software makes all the available computing & storage power is abstracted i.e., offering such computing & storage power away from the actual hardware which in turn will empower users to access such components with the help of a GUI.

Resources

  1. https://www.tutorialworks.com/kubernetes-vs-docker/

  2. https://medium.com/@saschagrunert/demystifying-containers-part-i-kernel-space-2c53d6979504