Container Basics
What are Containers?
Containers are lightweight, standalone, executable packages that include everything needed to run a piece of software, including the code, runtime, system tools, libraries, and settings. As a core container technology, they provide consistent and efficient application virtualization across different computing environments.
Key Container Concepts
Concept |
Description |
Isolation |
Containers run in isolated user spaces |
Portability |
Can run consistently across different platforms |
Efficiency |
Lightweight compared to traditional virtual machines |
Docker 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=$(dpatch -s)] $(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
## Pull an image
docker pull ubuntu:latest
## List 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 Workflow Visualization
graph TD
A[Developer Writes Code] --> B[Create Dockerfile]
B --> C[Build Container Image]
C --> D[Push to Container Registry]
D --> E[Deploy Container]
E --> F[Run Application]
Container Use Cases
Containers excel in software packaging and deployment across various scenarios:
- Microservices architecture
- Continuous integration/deployment
- Cloud-native applications
- Development and testing environments