What is Docker?
Docker is a platform for building, shipping, and running applications in containers. Containers package an application with all its dependencies, ensuring it runs consistently across any environment.
Why Docker for DevOps?
- Consistency — "Works on my machine" is solved
- Isolation — Applications don't interfere with each other
- Portability — Run anywhere Docker is installed
- Efficiency — Lighter than virtual machines
- Scalability — Easy to scale with orchestrators
Containers vs Virtual Machines
┌─────────────────────────────────┐
│ Virtual Machines │
├────────┬────────┬────────┬──────┤
│ App A │ App B │ App C │ │
│ Bins │ Bins │ Bins │ │
│Guest OS│Guest OS│Guest OS│ │
├────────┴────────┴────────┤ │
│ Hypervisor │ │
├───────────────────────────┤ │
│ Host OS │ │
└───────────────────────────┘ │
┌─────────────────────────────────┐
│ Containers │
├────────┬────────┬────────┬──────┤
│ App A │ App B │ App C │ │
│ Bins │ Bins │ Bins │ │
├────────┴────────┴────────┤ │
│ Docker Engine │ │
├───────────────────────────┤ │
│ Host OS │ │
└───────────────────────────┘
Containers share the host OS kernel, making them much lighter and faster to start.
Installing Docker
# Ubuntu
sudo apt update
sudo apt install docker.io -y
# Start and enable Docker
sudo systemctl start docker
sudo systemctl enable docker
# Add your user to the docker group
sudo usermod -aG docker $USER
# Log out and back in, then verify
docker --versionYour First Container
# Run a hello-world container
docker run hello-world
# Run an interactive Ubuntu container
docker run -it ubuntu bash
# Inside the container:
cat /etc/os-release
exitDocker Architecture
| Component | Role |
|---|---|
| Docker Client | CLI tool (docker command) |
| Docker Daemon | Background service managing containers |
| Images | Read-only templates for containers |
| Containers | Running instances of images |
| Registry | Storage for Docker images (Docker Hub) |
Essential Commands
# List running containers
docker ps
# List all containers (including stopped)
docker ps -a
# List downloaded images
docker images
# Pull an image
docker pull nginx
# Run a container in background
docker run -d -p 8080:80 nginx
# Stop a container
docker stop <container_id>
# Remove a container
docker rm <container_id>Summary
You've learned:
- What containers are and how they differ from VMs
- How to install Docker
- How to run your first container
- Docker's architecture and essential commands
Next Steps
Next, we'll learn about Dockerfiles — how to build your own custom container images.