Docker Overview

Jul 4, 2024

Docker Overview

Introduction

  • Docker: essential for software engineers, full-stack developers, backend developers, and DevOps engineers.

Background

  • First encountered Docker when working with VMs.
  • Docker is essential to solve common development process issues.
  • Key topics: Docker's necessity, Docker vs. VMs, basic Docker commands.

Key Problems in Development Without Docker

  1. Environment Reproduction: Issues arise when replicating local environments across different machines.
    • Example: Setting up same environment on different OS (e.g., Windows to Mac) with different versions of dependencies.
  2. Manual Errors: Setting up dependencies manually can lead to errors.
  3. Version Specificity: Some applications require specific versions to run (e.g., NodeJS 16 only).
  4. System Compatibility: Commands or dependencies may not work the same across different OS.
  5. Large Development Teams: Difficult to ensure the same setup across all developer systems.
  6. Production Servers: Same environment needs to be replicated on production servers, which introduces more issues.

Docker Solution

  • Helps to package applications with their dependencies in containers.
  • Containers are portable and lightweight.
  • No need to worry about OS differences when sharing these containers.

Concepts of Docker

  1. Containers: Self-contained units with application code and dependencies.
    • Portable across different machines (macOS, Windows, Linux, etc.).
    • Lightweight, easy to build, update, destroy, and share.
  2. Docker Platform: Service to build, destroy, and manage containers.
    • Containers can be shared easily among team members and production servers.
  3. Docker Desktop: GUI tool to manage Docker images and containers.
  4. Docker Hub: Repository for Docker images, similar to GitHub for code.
    • Docker images can be pulled from Docker Hub using docker pull command.

Practical Docker Usage

  1. Basic Commands:
    • docker pull <image_name>: Pulls a Docker image from Docker Hub.
    • docker run <image_name>: Runs a Docker image, creating a container.
    • docker stop <container_id>: Stops a running container.
  2. Example: Running hello-world and ubuntu images as containers.
    • Pulling and running a hello-world image.
    • Pulling and running an ubuntu image in interactive mode for executing commands inside the container.

Containers vs Virtual Machines

  1. Docker Containers:
    • Use the host operating system's kernel.
    • Only virtualize the application layer.
    • Lightweight and faster.
    • Size usually in MBs.
  2. Virtual Machines:
    • Have their own operating system kernel.
    • Virtualize both application and OS layers.
    • Heavier and slower.
    • Size usually in GBs.
    • VM Hypervisors provide full OS compatibility.

Common Misconceptions

  • Docker Desktop adds a lightweight hypervisor to facilitate lightweight system usage.
  • Docker is not a replacement for VMs; both serve different purposes.

Conclusion

  • Docker simplifies the development environment setup.
  • Facilitates sharing and running applications consistently across various environments.
  • Essential for modern software development practices, especially in large teams and production deployments.