Docker has become the de facto standard when it comes to container-based implementations. Docker is the base for container-based orchestration from small-scale implementations to large-scale enterprise applications.
Docker gained so much popularity in this fast-growing IT world. And organizations are continuously adopting it in their production environment because it’s developed for portability and designed for modern microservice architecture.
In this blog, you will learn,
- History Before Containerization
- What is Docker?
- What are the key features of Docker?
- Docker Architecture
- What is the Docker engine?
1.History Before Containerization
Containerization is a process of isolating applications into lightweight, self-contained units that are easy to deploy and manage. This process was first pioneered in the 1970s by developers working on Unix systems.
Before containerization, developers had to package their applications into virtual machines (VMs), which were bulky and difficult to manage. With containerization, developers can package their applications into containers, which are much smaller and easier to manage.
Before containers, there was a time when every application ran on its own server. This meant that each application had its own operating system, file system, and memory. This made it very difficult to move applications between servers.
Containerization changed all of that. With containers, applications are packaged into a single file that can be easily moved between servers. This makes it much easier to deploy and manage applications.
2.What is Docker?
Docker is a containerization tool that allows developers to create, deploy, and run applications within a container. A container is a self-contained software unit that includes everything needed to run an application, such as code, system tools, runtime, system libraries, etc.
3.What are the key features of Docker?
Here are some key features that make Docker so popular:
- Docker allows us to assemble applications from components faster and eliminates the errors that can come when shipping the code. Suppose we have two Docker containers running on different versions of the same app on the same operating system.
- Docker allows us to test the code before deploying it to production as soon as possible.
- Docker is simple to use. We can start with Docker on a minimal Linux, Mac, or Windows system running directly with a compatible Linux kernel or in a Virtual Machine with a Docker binary.
- We can “dockerize” our application in a few hours. Mostly Docker containers can be launched within a minute.
- Docker containers run everywhere. We can deploy containers on desktops, virtual machines, physical servers, data centres, and up to public and private clouds. And also, we can run the same containers everywhere.
Docker uses a client-server architecture. The Docker client communicates with the Docker daemon, which performs the tasks required to create and run your Docker containers. The Docker client and Docker daemon can run on the same system, or the daemon can be hosted on a remote server. The Docker client and Docker daemon communicate using a REST API over UNIX sockets. Another Docker client is Docker Compose, which lets you work with applications consisting of a set of containers.
The architecture of Docker consists of Docker Client, Docker Host, and Docker Registry. The roles and functions of each are explained below.
- Docker Client
The Docker client is the primary way that many Docker users communicate with Docker. The Docker client uses commands and REST APIs to communicate with the Docker Daemon (Server). When a client runs any docker command on the docker client terminal, the client terminal sends these docker commands to the Docker daemon. The Docker daemon receives these commands from the docker client through command and REST API requests.
Docker Client uses Command Line Interface (CLI) to run the following commands –
docker build- Build a Docker image from a Dockerfile
docker pull- Pulls an image or repository from a registry
docker run- Runs a container from an image
- Docker Host
A Docker host helps to execute and run container-based applications. It helps manage images, containers, networks, and storage volumes. As a crucial component, the Docker daemon performs essential container-running functions and receives commands from either the Docker client or other daemons to get its work done.
- Docker Daemon
The Docker daemon is a process used to manage and control the containers. The Docker daemon listens to only Docker API requests and handles Docker images, networks, containers, and volumes. A Docker daemon can also interact with other daemons to manage Docker services.
- Docker Images
A Docker image is a read-only template that contains a set of instructions for creating a Docker container. It includes everything needed to run an application–the code, a runtime, dependencies, environment variables, and configuration files.
Images are used to store and ship applications. Images can be created using the build command and can be pushed to a registry to share with others.
Docker images are typically created by reading a Dockerfile. A Dockerfile is a text file that contains all the commands you would normally execute manually to build a Docker image. These commands are used to pull base images, install the necessary software, run commands, and more. Once your Dockerfile is created, you can use the docker build command to create your image.
This is why images are lightweight, small, and fast compared to other virtualization technologies.
- Docker Containers
Docker containers are self-contained units of software that include everything an application needs to run. This includes the application code, runtimes, dependencies, and other files required for the application to run.
Docker containers are isolated from each other and the host operating system. This makes them much more portable and efficient than traditional virtual machines.
Docker containers are built on top of Docker images. A Docker image is a template that contains all the files and dependencies an application needs to run.
When you run a Docker image, it creates a Docker container. The container is a self-contained runtime environment for the application.
- Docker Registry
The Docker Registry is a service that stores and distributes Docker images. You can think of it as a repository for Docker images.
The Docker Registry is a central place to store and share your images. It’s public, so anyone can pull images from it. When you execute the docker pull or docker run commands, the required images are pulled from your configured registry. When you execute the docker push command, your image is pushed to your configured registry.
The Docker Registry is perfect for sharing your images with the world. But what if you want to keep your images private? Or share them with only a few people?
That’s where Docker Hub comes in. Docker Hub is a private Docker Registry that you can use for storing and sharing your images. It’s like a GitHub for Docker images.
Docker Hub is perfect for keeping your images private. And it’s free to use for personal repositories. But if you want to use it for commercial purposes, there is a small fee.
5.What is the Docker engine?
Docker engine is an open-source containerization tool that can help you to create and deploy applications in a very efficient way. With the Docker engine, you can package your application into a container and run it on any supported platform. This makes it very easy to deploy your applications consistently.
Docker Engine is a client-server-based application with the following components Docker server, REST API, and command line interface –
Docker server- A server that is a continuously running service called a daemon process.
REST API- A REST API that interfaces the programs to use talk with the daemon and instructs it on what to do.
A Dockerfile is a text file consisting of all commands the user can call on the command line to build an image. Use the base Docker image to add and copy files, run commands and expose the ports. The docker file can be considered the source code and images to compile for our container, which is running code. The Dockerfile is a portable file that can be shared, stored, and updated as required.
Here is an example of a Dockerfile.
RUN make /app
CMD python /app/app.py
Some of the docker files instruction are –
FROM – This is used to set the base image for the instructions. It is very important to mention this in the first line of the Dockerfile.
MAINTAINER – This instruction indicates the author of the docker file and its non-executable.
RUN – This instruction allows us to execute the command on top of the existing layer and create a new layer with the result of command execution.
CMD – This instruction doesn’t perform anything during the docker image building. It Just specifies the commands that are used in the image.
LABEL – This Instruction is used to assign the metadata as key-value pairs. It is always best to use as few LABEL instructions as possible.
EXPOSE – This instruction is used to listen on specific as required by application servers.
ENV – This instruction is used to set the environment variables in the Dockerfile for the container.
COPY – This instruction is used to copy the files and directory from a specific folder to the destination folder.
WORKDIR – This instruction sets the current working directory for the other instruction, i.e., RUN, CMD, COPY, etc.
A container is a self-contained software unit that includes everything needed to run an application, such as code, system tools, runtime, system libraries, etc. Docker is a containerization tool that allows developers to create, deploy, and run applications within a container. In this blog post, you will understand what Docker is and their key features. And also, we’ve covered the Docker Architecture, Docker engine, and Dockerfile and their instructions.