Docker Basics
What is Docker?
Docker is an open-source platform designed to automate the deployment, scaling, and management of applications using containerization technology. It allows developers to package an application with all its dependencies into a standardized unit called a container.
Key Docker Concepts
Containers
A container is a lightweight, standalone, executable package that includes everything needed to run an application: code, runtime, system tools, libraries, and settings.
graph TD
A[Application Code] --> B[Container]
C[Dependencies] --> B
D[System Libraries] --> B
E[Runtime Environment] --> B
Docker Images
Docker images are read-only templates used to create containers. They serve as the basis for container creation and can be stored in registries like Docker Hub.
Docker Architecture
Component |
Description |
Docker Client |
Command-line interface for interacting with Docker |
Docker Daemon |
Background service managing Docker objects |
Docker Registry |
Storage and distribution system for Docker images |
Why Use Docker?
- Consistency across different environments
- Lightweight and fast deployment
- Easy scalability
- Improved resource utilization
- Simplified configuration management
Docker Installation on Ubuntu 22.04
To install Docker on Ubuntu, use the following commands:
## 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 https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
## Set up the stable repository
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(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
Verifying Docker Installation
After installation, verify Docker is working correctly:
## Check Docker version
docker --version
## Run hello-world container
sudo docker run hello-world
Docker Workflow
graph LR
A[Develop] --> B[Build Image]
B --> C[Push to Registry]
C --> D[Pull Image]
D --> E[Run Container]
Getting Started with LabEx
LabEx provides interactive Docker learning environments that help developers practice and understand containerization technologies more effectively.