Day 18: Mastering Docker
Dec 11, 2024
•10:43 PM GMT+8
Containers have revolutionized how we develop, deploy, and manage applications by offering lightweight, portable environments that encapsulate software and its dependencies. DevOps practices are core to Docker's success as the industry leader in containerization.
What is Container?
- Lightweight and standalone: Containers package code, runtime, libraries, and system tools to run applications.
- Efficient: They share the host OS's kernel, using fewer resources than virtual machines.
- Consistent: Ensure applications run the same across development, testing, and production.
- Focus on applications: Simplify building, deploying, and managing applications without environment-specific issues.
Virtual Machine vs Container
Below is a comprehensive list of Python libraries frequently used in DevOps for various tasks such as automation, configuration management, testing, and cloud integration:
Feature | Description | Container |
Definition | A virtualized hardware environment that emulates a physical machine | A standardized software unit that packages code and its dependencies, allowing it to run consistently across different environments |
Operating System | Each VM has its own OS | Containers share the host OS kernel |
Resource Allocation | VMs have dedicated hardware resources | Containers share the host's hardware resources |
Boot Time | Slower boot time due to OS loading | Faster boot time as they don't need to boot an OS |
Portability | Less portable as they require specific hardware and OS configurations | Highly portable, can run on any system with a compatible container runtime |
Isolation | Strong isolation, each VM is independent | Less isolation, containers rely on the host OS for security |
Resource Overhead | Higher resource overhead due to the full OS | Lower resource overhead as they share the host OS |
Use Cases | Ideal for legacy applications, complex software stacks, and hardware-specific requirements | Well-suited for microservices architecture, cloud-native applications, and rapid deployment |
What is Docker?
Docker is an open-source platform designed to simplify application development, deployment, and management using containerization technology. It allows developers to package applications and their dependencies into a lightweight, portable container that can run consistently across different environments.
Docker Engine
The Docker Engine is the core component of Docker, responsible for building, running, and managing containers. It acts as a lightweight runtime and ensures containers operate efficiently by abstracting the underlying operating system.
Docker Engine consists of three main components:
- Docker Daemon (
dockerd
): A background service that manages Docker objects such as images, containers, and networks. It handles container lifecycle operations like starting, stopping, and removing containers. - Docker CLI: The command-line interface through which users interact with the Docker Engine. It simplifies tasks such as building images, managing containers, and pushing or pulling images from Docker Hub.
- REST API: Provides programmatic access to Docker functionality, allowing integration with other tools and automation of container operations.
By combining these components, Docker Engine offers a powerful and user-friendly way to manage containerized applications, ensuring scalability, portability, and efficiency.
Docker Containers
Docker containers are lightweight, portable environments that run on the Docker Engine. They package applications and their dependencies together, ensuring they work consistently across any system.
- Standard: Docker containers adhere to open standards, ensuring compatibility and interoperability across different platforms and tools. This consistency is critical for seamless development and deployment.
- Lightweight: Unlike virtual machines, containers share the host operating system kernel, eliminating the need for a full OS inside each container. This design significantly reduces resource usage and start-up time.
- Secure: Containers run in isolated environments, separating applications from the host system and from each other. This isolation minimizes risks and ensures better control over security policies.
Docker Installation
Docker can be installed on various operating systems, with the most common platforms being Linux and Windows. Below are the installation steps for both:
Docker Installation on Linux (Ubuntu 22.04)
- Update the system and Set up Docker's
apt
repository
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
- Install the Docker packages
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
- Verify Installation
docker --version
systemctl status docker
Docker Installation on Windows
- Download Docker Desktop for Windows
Visit Docker Windows installer and download Docker Desktop for Windows. - Install Docker Desktop
Run the installer and follow the on-screen instructions. Ensure that WSL 2 (Windows Subsystem for Linux) and Hyper-V are enabled during installation. - Configure WSL 2
Docker Desktop requires WSL 2 to run on Windows. You can enable it via PowerShell:
wsl --install
- Launch Docker Desktop
Once installed, launch Docker Desktop. It may take a few moments to start.
docker --version
Final Thoughts
In this blog, we explored Docker's essential components, including the differences between virtual machines and containers, the core functionality of Docker Engine, and the lightweight, secure nature of Docker containers. We also walked through the installation process for both Linux and Windows, equipping you to start using Docker in your projects.
In the next blog, we will take things further by mastering Docker commands and diving deeper into core Docker concepts, empowering you to manage containers and images effectively. Stay tuned!
Day 18: Mastering Docker
Master Docker with insights on containers, Docker Engine, installation steps for Linux and Windows, and container advantages.
For the passion of automated cloud solutions.
Subscribe to get the latest posts. I mostly write about Backend (Python/Bash), DevOps and Linux.