Docker is a software platform for packaging, distributing, and running applications inside containers.
Containers ensure that applications run the same way regardless of the environment, eliminating compatibility issues and enabling predictable, consistent behavior across different systems.
Key benefits:
- Runs on any machine, OS, or cloud without modification.
- Supports any programming language and technology stack.
- Reduces deployment complexity and maintenance overhead.
Typical use cases:
- Running microservices architectures.
- Migrating legacy applications from on-premises to the cloud (βlift-and-shiftβ).
Docker on an Operating System
Docker runs directly on an operating system (e.g., an EC2 instance) and manages containers.
Each container includes:
- The application code.
- All required dependencies.
- The runtime environment.
Core principle:
Containers share the host OS kernel, making them far more lightweight and faster to start than virtual machines.
Advantages:
- Efficient resource utilization.
- Rapid startup times.
- Application isolation for security and stability.
Where are Docker Images Stored?
Docker images are stored in repositories. These can be public or private.
Docker Hub
- Public image registry.
- Offers official base images for popular operating systems and software (e.g., Ubuntu, MySQL).
- Serves as a central source for sharing and discovering container images.
Amazon ECR
Docker vs. Virtual Machines
Docker provides container-based virtualization, which is fundamentally different from traditional hardware virtualization used by virtual machines (VMs).
Traditional Virtual Machines
- Stack: Infrastructure β Host OS β Hypervisor β Guest OS β Application
- Each VM contains a full guest OS, making it resource-heavy.
- Slower startup times due to OS boot process.
Docker Architecture
- Stack: Infrastructure β Host OS (e.g., EC2) β Docker Daemon β Container (App + Dependencies)
- Containers share the host OS kernel, so no separate guest OS is needed.
- Much more lightweight and faster to start than VMs.
Key takeaway:
VMs are better for strong isolation between workloads with different OS requirements, while Docker excels in speed, efficiency, and portability for applications that can share the same OS kernel.
Getting Started with Docker
Basic Workflow
- Dockerfile
Defines the instructions for building a Docker image, including base image, dependencies, environment variables, and commands.
- Build
Run
docker build
to create an image from the Dockerfile.- Run
Start a container from the image using
docker run
. Containers are isolated, portable environments for running your application.- Push
Upload the image to a Docker repository (e.g., Amazon ECR) for storage and distribution.
- Pull
Download the image from the repository to run it on another machine or environment.
Docker Repository
A storage system for Docker images. It can be public (e.g., Docker Hub) or private (e.g., Amazon ECR).
This workflow ensures applications are packaged consistently, shared easily, and deployed reliably across different environments.