Contents
Introduction
In this blog, we are going to see how we achieve containerization with the help of Docker. And learn about the Docker Architecture, Components, Benefits and Basic Commands.
Docker Concepts
What is Containerization?
Containerization is a software deployment process that bundles an application’s code with all the files and libraries it needs to run on any infrastructure. Traditionally, to run any application on your computer, you had to install the version that match your machine’s operating system. For example, you need to install the Windows version of a software package on a Windows machine. However, with containerization, you can create a single software package, or container, that runs on all types of devices and operating systems.
What is Virtualization?
Virtualization is a technology in which an application, data storage or guest operating system is abstracted from the truly underlying software or hardware.
What is Docker?
Docker is a software development platform for virtualization with multiple Operating systems running on the same host. It helps to separate infrastructure and applications to deliver software quickly.
Docker packages software into standardized units called containers that have everything the software needs to run including libraries, system tools, code, and runtime. Using Docker, you can quickly deploy and scale applications into any environment and know your code will run. Docker container technology was launched in 2013 as an open-source Docker Engine.
What are Containers?
Containers, or Linux Containers, are a technology that allows us to isolate certain kernel processes and trick them into thinking they're the only ones running in a completely new computer.
Different from Virtual Machines, a container can share the kernel of the operating system while only having their different binaries/libraries loaded with them.
Containers uses Operating system level virtualization for deploying applications instead of creating an entire VM. In other words, you don't need to have whole different OS (called guest OS) installed inside your host OS. You can have several containers running within a single OS without having several different guests OS's installed.
Comparing Containers and Virtual Machines
Containers and virtual machines have similar resource isolation and allocation benefits, but function differently because containers virtualize the operating system instead of hardware. Containers are more portable and efficient.
What Is Docker Used For?
· Running multiple workloads on fewer resources.
· Isolating and segregating applications.
· Standardizing environments to ensure consistency across development and release cycles.
· Streamlining the development lifecycle and supporting CI/CD workflows.
· Developing highly portable workloads that can run on multi-cloud platforms.
Why Docker?
· Docker makes development efficient and predictable.
· Docker takes away repetitive, mundane configuration tasks and is used throughout the development lifecycle for fast, easy and portable application development – desktop and cloud.
· Docker’s comprehensive end to end platform includes UIs, CLIs, APIs and security that are engineered to work together across the entire application delivery lifecycle.
· Docker is also a cost-effective alternative to virtual machines.
How Docker works?
Docker works by providing a standard way to run your code. Docker is an operating system for containers. Similar to, how a virtual machine virtualizes (removes the need to directly manage) server hardware, containers virtualize the operating system of a server. Docker is installed on each server and provides simple commands you can use to build, start, or stop containers.
When to use Docker?
You can use Docker containers as a core building block creating modern applications and platforms. Docker makes it easy to build and run distributed microservices architectures, deploy your code with standardized continuous integration and delivery pipelines, build highly-scalable data processing systems, and create fully-managed platforms for your developers
How to use Docker?
Let us see steps on how to get started with Docker.
· Build and run an image as a container.
· Share images using Docker Hub.
· Deploy Docker applications using multiple containers with a database.
· Run applications using Docker Compose.
Docker Architecture
Docker makes use of a client-server architecture. The Docker client talk with the docker daemon which helps in building, running, and distributing the docker containers. The Docker client run with the daemon on the same system or we can connect the docker client with the docker daemon remotely. With the help of REST API over a UNIX socket or a network, the docker client and daemon interact with each other.
1. Docker Client
2. Docker Host
3. Network and Storage components
4. Docker Registry / Hub
1)The Docker Client
The Docker client enables users to interact with Docker. The Docker client can reside on the same host as the daemon or connect to a daemon on a remote host. A docker client can communicate with more than one daemon. The Docker client provides a command line interface (CLI) that allows you to issue build, run, and stop application commands to a Docker daemon.
The main purpose of the Docker Client is to provide a means to direct the pull of images from a registry and to have it run on a Docker host. Common commands issued by a client are:
docker build
docker pull
docker run
2)Docker Host
A Docker host is a type of machine which is responsible for running more than one container.
It comprises of the
i. Docker Daemon
ii. Images
iii. Containers
i) Docker Daemon
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. It is a service that runs in the background that listens for Docker Engine API requests and manages Docker objects like images and containers. Docker Engine API is a RESTful API that's used to interact with Docker daemon.
ii)Docker Image
A Docker Image is an immutable (unchangeable) file that contains the source code, libraries, dependencies, tools, and other files needed for an application to run. An image contains instructions for creating a docker container. It is just a read-only template. It is used to store and ship applications. Images are an important part of the docker experience as they enable collaboration between developers in any way which is not possible earlier.
A Docker File is a script that consists of a set of instructions on how to build a Docker image. These instructions include specifying the operating system, languages, Docker environment variables, file locations, network ports, and other components needed to run the image. All the commands in the file are grouped and executed automatically.
iii) Docker Containers
Docker containers are lightweight virtualized runtime environments for running applications. They are independent and isolated from the host and other instances running on the host.
Containers are abstractions of the app layer. Each container represents a package of software that contains code, system tools, runtime, libraries, dependencies, and configuration files required for running a specific application. This makes it possible for multiple containers to run in the same host, so you can use that host's resources more efficiently.
Each container runs as an isolated process in the user space and take up less space than regular VMs due to their layered architecture.
3) Network and Storage components
Docker Storage
We can store data within the writable layer of the container but it requires a storage driver. Storage driver controls and manages the images and containers on our docker host. Keeping the persistent storage as a reference, docker offer 4 options:-
Data Volumes
Volume Container
Directory Mounts
Storage Plugins
Docker Networking
Docker networking provides complete isolation for docker containers. It means a user can link a docker container to many networks. It requires very less OS instances to run the workload.
There are primarily 5 network drivers in docker:
Bridge: It is the default network driver. We can use this when different containers communicate with the same docker host.
Host: When you don’t need any isolation between the container and host then it is used.
Overlay: For communication with each other, it will enable the swarm services.
None: It disables all networking.
macvlan: This network assigns MAC(Media Access control) address to the containers which look like a physical address.
4) Docker Registries
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.
Advanced Docker Components
· Docker-compose is designed for running multiple containers as a single service. It does so by running each container in isolation but allowing the containers to interact with one another. You would write the compose environments using YAML.
· Docker Swarm is a clustering and scheduling tool for Docker containers. At the front end, it uses the Docker API, which gives us a means of controlling it with various tools. It is composed of many engines that can both be self-organizing or pluggable depending on what requirements they’re trying to meet at any given point in time. Swarm enables you to use a variety of backends.
Docker Commands
Note: Anything enclosed within the square brackets is optional.
Benefits of Docker
· Faster and Easier configuration: Docker containers help to deploy and test applications in a drastically reduced amount of time and with fewer resources than if an entire database infrastructure had to be installed on a computer for it.
· Application isolation: Docker provides containers that aid developers in creating applications in an isolated environment. This independence allows any application to be created and run in a container, regardless of its programming language or configuration required.
· Increase in productivity: These containers are portable, self-contained, and they include an isolated disk volume so you can transport highly protected information without losing sight of what’s inside as the container is developed over time and deployed to various environments.
· Services: Services are an abstraction layer to make it easier for users to access the various orchestration systems. It serves as a gateway from higher-level formats such as OpenStack, NFV, or management software into the Swarm API. Each service record lists one instance of a container that should be running, and Swarm schedules them across the nodes.
· Security Management: Open-source software saves sensitive information into the cloud and allows people to give access to certain things such as open-source software platforms, like the one you may use that can create secret passes, etc.
· Rapid scaling of Systems: Containers don’t rely on their host configuration, rather they only rely on their contents and thus will run correctly regardless of what operating system or kernel they’re running on
· Better Software Delivery: The containers that make up the best software delivery system as it is one of the best and safest software delivery systems available at this moment. These containers are portable, self-contained, and they include an isolated disk volume to transport highly protected information.
· Software-defined networking: With the CLI (Command Line Interface) and Engine, you are able to define isolated networks for containers. In addition to this, designers and engineers can shape intricate network topologies, plus easily define them in configuration files also.
· Has the Ability to Reduce the Size: The size of an operating system is directly proportional to the number of applications installed in the system. Being a comparatively smaller footprint, containers will help to reduce the number of applications, and hence, the OS can be comparatively smaller.
Conclusion
Like other powerful technologies, Docker has its own drawbacks, but the net result has been a big positive for us, our teams, and our organization. If you implement the Docker workflow and integrate it into the processes you already have in your organization, there is every reason to believe that you can benefit from it as well.