In this blog, we will explore the concept of Docker and why it has become a popular choice for developers and organizations. Before diving into Docker, let's understand the challenges that led to its creation
The Need for Docker
In the past, companies used to deploy their applications on dedicated servers, resulting in underutilized resources. To address this issue, virtual machines (VMs) were introduced.
Virtual Machines (VMs)
VMs are isolated environments created through virtualization. They allow multiple operating systems to run on a single physical server, enabling better resource utilization. VMs are managed by hypervisors, which can be categorized into two types:
Type 1 Hypervisor:
Also known as the "bare-metal" hypervisor, it runs directly on the physical hardware of the host machine, providing direct access to the underlying hardware.
Type 2 Hypervisor:
Type 2 hypervisors are installed on an existing operating system, relying on the host machine's OS for certain operations like CPU, network, memory, and storage management.
However, VMs have their own set of challenges, such as wasting resources, slow startup and shutdown times, and running out of memory.
Containers
Containers provide a solution to the limitations of VMs. Think of a container as a shipping container that holds all the necessary components of an application, including frontend data, static data, and dependencies. Containers allow developers to package and ship applications easily without worrying about the underlying infrastructure.
Why Containers are Lightweight
Containers are lightweight because they don't require a full operating system like VMs. They use a minimal operating system base and create logical separation between containers, ensuring isolation and security.
Open Container Initiative (OCI)
The Open Container Initiative (OCI) is a collaborative project hosted by the Linux Foundation. It aims to establish common standards for container formats and runtimes, bringing together companies like Google and VMware.
What is Docker?
Docker is an open platform for developing, shipping, and running applications. It enables the separation of applications from infrastructure, allowing for faster software delivery. Docker provides an easy way to containerize applications through its rich user interface and command-line tools.
Why Docker is Famous
Docker gained popularity due to its user-friendly interface and simple commands for managing containers. It introduced the concept of Docker files, which are text documents containing all the commands and dependencies required to build an application image.
Docker Lifecycle
The Docker lifecycle consists of the following steps:
Docker file: A text document containing the set of instructions and dependencies for building the application.
Docker Build: The command that takes a snapshot of the application and creates a Docker image.
Docker Run: The command that runs the Docker image, creating a container.
Docker Hub: A platform for sharing Docker images, similar to GitHub for source code.
Docker Architecture
The Docker architecture consists of the following components:
Docker Client: The command-line interface for interacting with Docker.
Docker Daemon: Listens to Docker requests and manages Docker objects.
Docker Build: Builds Docker images from Docker files.
Docker Pull: Pulls Docker images from a registry.
Docker Run: Runs a container from a Docker image.
Docker Hub: A public registry for sharing Docker images.
Practical Example
Let's explore practical example of using Docker:
Step 1: Install Docker
Install Docker on your system using the following command:
ubuntu $ apt install docker.io
Reading package lists... Done
Building dependency tree
Reading state information... Done
docker.io is already the newest version (24.0.5-0ubuntu1~20.04.1).
0 upgraded, 0 newly installed, 0 to remove and 178 not upgraded.
Step 2: To check if Docker is installed on your system
Verify the installation by running docker --version
.
ubuntu $ docker --version
Docker version 24.0.5, build 24.0.5-0ubuntu1~20.04.1
Step 3: Run a Docker Container
Run a simple Docker container using the following command:
This command pulls the docker/whalesay
image from the public repository and runs the container.
ubuntu $ docker run docker/whalesay cowsay "learning docker"
Unable to find image 'docker/whalesay:latest' locally
latest: Pulling from docker/whalesay
Image docker.io/docker/whalesay:latest uses outdated schema1 manifest format. Please upgrade to a schema2 image for better future compatibility. More information at https://docs.docker.com/registry/spec/deprecated-schema-v1/
e190868d63f8: Pull complete
909cd34c6fd7: Pull complete
0b9bfabab7c1: Pull complete
a3ed95caeb02: Pull complete
00bf65475aba: Pull complete
c57b6bcc83e3: Pull complete
8978f6879e2f: Pull complete
8eed3712d2cf: Pull complete
Digest: sha256:178598e51a26abbc958b8a2e48825c90bc22e641de3d31e18aaf55f3258ba93b
Status: Downloaded newer image for docker/whalesay:latest
_________________
< learning docker >
-----------------
\
\
\
## .
## ## ## ==
## ## ## ## ===
/""""""""""""""""___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~
\______ o __/
\ \ __/
\____\______/
Step 4: List Docker Images and Containers
To list the Docker images and containers, use the following commands:
ubuntu $ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
368140a59c8b docker/whalesay "cowsay 'learning do…" About a minute ago Exited (0) About a minute ago mystifying_proskuriakova
Step 5: To delete a Docker container
To delete a Docker container, use the docker rm
command followed by the container's ID or name.
ubuntu $ docker rm 368140a59c8b
368140a59c8b
ubuntu $ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Conclusion
In this blog, we explored the concept of Docker and its role in simplifying application development and deployment. We discussed the challenges faced with traditional deployment methods and how virtual machines (VMs) and containers addressed those issues. We also learned about the Open Container Initiative (OCI) and its efforts to standardize container formats and runtimes.
Docker has gained popularity due to its user-friendly interface, rich command-line tools, and the ability to package applications along with their dependencies into containers. The Docker lifecycle, consisting of Docker files, Docker Build, Docker Run, and Docker Hub, provides a streamlined workflow for building, sharing, and running containerized applications.
Docker has revolutionized the way applications are developed, packaged, and deployed, enabling faster development cycles, improved scalability, and easier collaboration among teams.
I hope this blog has provided you with a basic understanding of Docker and its benefits. If you have any further questions or thoughts, feel free to leave a comment below.