Docker Containers Basics
What are Docker Containers?
Docker containers represent a lightweight, standalone, and executable software package that includes everything needed to run an application: code, runtime, system tools, libraries, and settings. Containerization technology enables developers to create consistent environments across different computing platforms.
Core Concepts of Containers
Containers provide isolation and efficiency compared to traditional virtual machines by sharing the host system's kernel while maintaining separate user spaces.
graph TD
A[Host Operating System] --> B[Docker Engine]
B --> C[Container 1]
B --> D[Container 2]
B --> E[Container 3]
Installation and Setup
To install Docker on Ubuntu 22.04, use the following commands:
sudo apt-get update
sudo apt-get install docker.io
sudo systemctl start docker
sudo systemctl enable docker
Basic Docker Commands
Command |
Description |
docker run |
Create and start a new container |
docker ps |
List running containers |
docker images |
Show available container images |
docker stop |
Stop a running container |
Creating Your First Container
Example of running an Ubuntu container:
docker run -it ubuntu:latest /bin/bash
This command downloads the latest Ubuntu image and launches an interactive bash shell inside the container. The -it
flags enable interactive terminal mode.
Container Lifecycle Management
Containers can be in different states: created, running, paused, stopped, or deleted. Docker provides commands to manage these states efficiently, ensuring flexible application deployment and resource utilization.