Virtualization Concepts
Virtualization is a resource management technology that abstracts physical computing hardware—such as servers, memory, network, and storage—into logical resources. By decoupling the software environment from the underlying physical infrastructure, users can achieve greater efficiency and flexibility. In production environments, this helps resolve issues related to hardware over-provisioning or the need to repurpose legacy hardware.
Key technologies in this space include KVM, VMware for software-based virtual machine management, and orchestration platforms like OpenStack. Docker and Kubernetes have emerged as the standard for modern container-based workflows.
Introduction to Docker
Docker, introduced in 2013 and built using Go, is an open-source platform that simplifies the packaging and deployment of applications through containerization. Unlike traditional hypervisor-based virtualization, Docker utilizes Linux kernel features such as namespaces and cgroups to isolate processes, allowing multiple containers to run efficiently on a single host.
Comparison: Containers vs. Virtual Machines
- Efficiency: Virtual machines require a full guest operating system, which is resource-intensive. Containers share the host's kernel and are significantly lighter, leading to faster startup times and lower overhead.
- Isolation: VMs provide hardware-level isolation, while containers provide process-level isolation. While VMs offer a more robust security boundary, containers are optimized for high-density, rapid-scaling deployments.
- Deployment: Docker allows for a standardized application package, ensuring that software behaves consistently across development, testing, and production environments.
Docker Architecture
Docker follows a client-server architecture:
- Client: The interface through which users execute commands.
- Daemon: The background service that manages containers, images, networks, and storage.
- Registry: A remote storage service for Docker images, such as Docker Hub.
Installation and Configuration
To install Docker on a CentOS system, execute the following steps:
# Remove existing versions
sudo yum remove docker docker-common docker-selinux docker-engine
# Add repository and install
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce docker-ce-cli containerd.io
# Start and enable service
sudo systemctl start docker
sudo systemctl enable docker
To optimize image downloads, configure a registry mirror in /etc/docker/daemon.json:
{
"registry-mirrors": ["https://your-mirror-url.com"]
}
Then, restart the daemon:
sudo systemctl daemon-reload
sudo systemctl restart docker
Managing Images and Containers
- Images: Think of images as immutable blueprints or classes. They are stored in registries and contain all dependencies required to execute an application.
- Containers: These are the runtime instances of images, analogous to objects in object-oriented programming. A single image can be instantiated into multiple running containers.
Basic Commands
- Downloading Images:
docker pull <image_name>:<tag> - Listing Local Images:
docker images - Creating and Starting a Container:
docker run -di --name <container_name> <image_name> - Listing Containers:
docker ps(active) ordocker ps -a(all) - Managing Lifecycle:
docker start <id>,docker stop <id>, anddocker rm <id> - Executing Commands Inside a Container:
docker exec -it <container_id> /bin/bash
Publishing Images
To share your images, login to a registry, tag your local build, and push it:
docker login
docker tag <local_image> <username>/<repository>:<tag>
docker push <username>/<repository>:<tag>