Docker Basics
Introduction to Docker and Container Technology
Docker is a powerful platform for containerization, enabling developers to package, distribute, and run applications consistently across different computing environments. As a key tool in modern software deployment, Docker simplifies the process of creating, managing, and scaling applications.
Core Concepts of Docker
graph TD
A[Docker Image] --> B[Docker Container]
A --> C[Dockerfile]
B --> D[Container Runtime]
Docker introduces several fundamental concepts:
Concept |
Description |
Docker Image |
Read-only template containing application code and dependencies |
Docker Container |
Runnable instance of an image |
Dockerfile |
Text file defining image build instructions |
Docker Registry |
Repository for storing and sharing 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 available 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>
Practical Example: Running a Simple Web Application
## Pull Nginx image
docker pull nginx:latest
## Run Nginx container
docker run -d -p 8080:80 nginx:latest
## Verify container is running
docker ps
This example demonstrates how to quickly deploy a web server using Docker, showcasing its simplicity and efficiency in software deployment.