Docker Basics
What is Docker?
Docker is a powerful containerization technology that enables developers to package, distribute, and run applications consistently across different computing environments. As a fundamental tool in modern software development, Docker simplifies application deployment and enhances system efficiency.
Core Concepts of Containerization
Containerization allows applications to be isolated and run independently with their own dependencies. Unlike traditional virtual machines, containers share the host system's kernel, making them lightweight and fast.
graph TD
A[Application Code] --> B[Docker Container]
B --> C[Shared Host Kernel]
B --> D[Isolated Environment]
Docker Architecture
Component |
Description |
Docker Daemon |
Background service managing containers |
Docker Client |
Command-line interface for interacting with Docker |
Docker Images |
Read-only templates for creating containers |
Docker Containers |
Runnable instances of 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=$(dpkg --print-architecture) 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
First Docker Container Example
## Pull official Ubuntu image
docker pull ubuntu:latest
## Run interactive container
docker run -it ubuntu:latest /bin/bash
## Inside container, verify environment
cat /etc/os-release
This example demonstrates how to download an Ubuntu image and run an interactive container, showcasing Docker's simplicity in creating isolated environments.