DEV Community

Harish I J
Harish I J

Posted on

2

Docker 101 ft. Avg Web Dev

Image description

Docker is a game-changer for modern application development, offering a lightweight and efficient alternative to traditional virtual machines. This article explores the core differences between Docker containers and hypervisor-based virtualization, while providing a practical guide on how to dockerize and streamline your applications. Whether you're a beginner or an experienced developer, you'll find essential Docker commands and insights to enhance your development workflow.

Docker vs. Traditional Virtualization: Understanding the Differences

Docker has revolutionized application development, deployment, and management through its lightweight, portable containers. While Docker containers share similarities with traditional virtual machines (VMs), they differ fundamentally in their architecture and performance characteristics.

What is a Hypervisor?

A hypervisor is virtualization software that creates and manages virtual machines (VMs). It enables multiple operating systems to run simultaneously on a single physical machine by abstracting hardware resources.

Types of Hypervisors

  1. Type 1 (Bare Metal): Runs directly on the host hardware without a host operating system. Examples include:
  2. Type 2 (Hosted): Runs on a host operating system, providing virtualization capabilities. Examples include:

Docker vs. Hypervisor-based Virtualization

Feature Traditional Virtualization (Hypervisor) Docker (Container Virtualization)
Virtualization Level Hardware-level virtualization Operating system-level virtualization
OS Overhead Each VM runs a full OS instance Shares the host OS kernel
Resource Usage Higher (due to full OS overhead) Lower (lightweight and minimal)
Startup Time Minutes Seconds
Isolation Strong (hardware-level) Process-level (shares the host kernel)
Performance Slower (due to emulating hardware) Faster (directly uses host resources)

Architectural Comparison

Hypervisor-based VM:
  Hardware → Host OS → Hypervisor → Guest OS → App

Docker Container:
  Hardware → Host OS → Docker Engine → Container → App
Enter fullscreen mode Exit fullscreen mode

https://airflow.apache.org/docs/docker-stack/_images/docker-logo.png

Docker's lightweight design enables better performance and faster deployment, though it provides slightly less isolation than VMs.

Docker Overview

Docker is a platform for building, shipping, and running applications in containers. These containers package applications with their dependencies, ensuring consistent behavior across environments.

Key Docker Concepts

  • Container: A lightweight, standalone executable package.
  • Image: A read-only blueprint for creating containers.
  • Dockerfile: A script defining how to build Docker images.
  • Registry: A storage hub for sharing Docker images (e.g., Docker Hub).
  • Docker Compose: A tool to manage multi-container applications.

Learn more in the Docker documentation.

Advantages of Docker

  • Consistency: Ensures consistent application behavior across environments.
  • Efficiency: Lightweight containers require fewer resources than VMs.
  • Portability: Works on any system supporting Docker.
  • Scalability: Easily scales horizontally across multiple systems.
  • Isolation: Containers operate independently from one another.

Essential Docker Commands

# Run a container
docker run [OPTIONS] IMAGE [COMMAND]

# List running containers
docker ps

# List all containers (including stopped ones)
docker ps -a

# Build an image from a Dockerfile
docker build -t image_name:tag .

# Push an image to a registry
docker push image_name:tag

# Pull an image from a registry
docker pull image_name:tag

# Run a container in the background
docker run -d image_name:tag

# Stop a running container
docker stop container_id

# Expose a container's port to the host
docker run -d -p local_port:container_port image_name:tag

# Remove a container
docker rm container_id

# Remove an image
docker rmi image_name

# List Docker volumes
docker volume ls

# Remove a Docker volume
docker volume rm volume_name

# Clean up stopped containers
docker container prune

# Log in to Docker Hub
docker login
Enter fullscreen mode Exit fullscreen mode

For a full command reference, check the Docker CLI documentation.

Docker Compose

Docker Compose simplifies managing multi-container Docker applications using a compose.yaml file.

# Initialize Docker in a project
docker init

# Start services defined in docker-compose.yaml
docker compose up
Enter fullscreen mode Exit fullscreen mode

Example compose.yaml configuration for managing volumes:

services:
  web:
    image: node:18
    volumes:
      - .:/app
      - /app/node_modules
Enter fullscreen mode Exit fullscreen mode

Learn more in the Docker Compose documentation.

Docker Compose Watch

docker compose watch automatically rebuilds and restarts services on code changes.

# Watch for changes and sync them
docker compose watch
Enter fullscreen mode Exit fullscreen mode

Explore Docker Compose Watch in the official guide.

Docker Scout

Docker Scout enhances container security by scanning for vulnerabilities and providing detailed reports.

Features

  • Vulnerability Scanning: Detects security risks in images.
  • SBOM (Software Bill of Materials): Lists software components in an image.
  • CI/CD Integration: Automates security checks in pipelines.
  • Policy Enforcement: Ensures only secure images are deployed.

Docker Scout Commands

# Scan an image for vulnerabilities
docker scout cves image_name:tag

# Generate an SBOM report
docker scout sbom image_name:tag

# Compare security between images
docker scout compare image1:tag1 image2:tag2
Enter fullscreen mode Exit fullscreen mode

Discover more in the Docker Scout documentation.

Docker GUI / Desktop App

Docker Desktop is the official graphical user interface for Docker, offering a comprehensive suite of tools for container development and management. It includes:

Core Components

  • Docker Engine: The container runtime environment that powers everything
  • Docker CLI: Command-line interface accessible through an integrated terminal
  • Docker Compose: Tool for defining and running multi-container applications
  • Docker BuildKit: Advanced image building system

Development Tools

  • Dashboard: Visual interface for managing containers, images, volumes, and networks
  • Dev Environments: Create isolated development environments from Git repositories
  • Docker Extensions: Marketplace for adding new features and integrations
  • Container Terminal: Direct access to running containers

Built-in Features

  • Kubernetes: Single-node Kubernetes cluster for local development
  • Volume Management: GUI for creating and managing persistent data volumes
  • Image Management: Pull, build, and push container images
  • Network Controls: Create and manage container networks

System Requirements

For Windows:

  • Windows 10/11 64-bit: Pro, Enterprise, or Education
  • WSL 2 backend enabled
  • Hardware virtualization support (BIOS-enabled)

For macOS:

  • macOS 11 or newer (Intel or Apple Silicon)
  • At least 4GB RAM (8GB recommended)

Docker Desktop is available for personal use and small business teams. Enterprise licenses are required for larger organizations.

Conclusion

Understanding the differences between Docker containers and traditional hypervisor-based virtualization helps you make better architectural decisions. Docker's efficiency, portability, and ease of use make it a powerful tool for modern application development.

For more detailed information, visit the official **Docker documentation.**


by Harish I J

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay