Docker Basics
Introduction to Docker
Docker is a powerful platform for software containerization, enabling developers to package, distribute, and run applications consistently across different computing environments. As a container technology, Docker simplifies application deployment and improves system efficiency.
Core Concepts
Docker uses lightweight containers to isolate applications and their dependencies. Unlike traditional virtual machines, containers share the host system's kernel, making them more resource-efficient.
graph TD
A[Application] --> B[Docker Container]
B --> C[Host Operating System]
C --> D[Hardware]
Key Components
Component |
Description |
Docker Engine |
Core runtime environment |
Docker Image |
Read-only template for containers |
Docker Container |
Runnable instance of an image |
Dockerfile |
Script for building Docker images |
Installation on Ubuntu 22.04
## Update package index
sudo apt update
## Install dependencies
sudo apt install apt-transport-https ca-certificates curl software-properties-common
## Add Docker's official GPG key
curl -fsSL | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
## Set up stable repository
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
## Install Docker Engine
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io
Basic Docker Commands
## Check Docker version
docker --version
## Pull an image from Docker Hub
docker pull ubuntu:latest
## List local images
docker images
## Run a container
docker run -it ubuntu:latest /bin/bash
## List running containers
docker ps
## Stop a container
docker stop container_id
Container Lifecycle Management
Docker provides a complete lifecycle management system for containers, allowing developers to create, start, stop, and remove containers efficiently. This approach supports continuous integration and deployment workflows.
Containers offer significant advantages over traditional virtualization:
- Faster startup times
- Lower resource consumption
- Consistent environment across development and production
- Easy scalability and portability