Docker Essentials: A
Comprehensive Guide
By Ravi Kiran Maroju
RK by Ravi Kiran
What is Docker?
By Ravi Kiran Maroju
Magic Box for Software Pack an App
Docker is like a magic box for It lets us pack an app with
software. everything it needs (like
tools, files, settings) so it can
run anywhere 3 on your
computer or on someone
else's.
Lunchbox Analogy
Think of it like a lunchbox: you put food (the app) and utensils (tools it
needs) in it, so you're ready to eat (run it) anywhere!
Docker vs Virtual Machines (VMs)
Feature Docker (Containers) Virtual Machines (VMs)
Speed Very fast Slower
Size Small (~MBs) Big (~GBs)
Uses OS Shares host OS Has its own OS
Resource Usage Low High
Containers are light and quick, like bicycles.
VMs are heavy and slow, like trucks.
By Ravi Kiran Maroju
Docker Architecture
Easy analogy: Running a puppet show
By Ravi Kiran Maroju
Docker Client
You (puppet master) tell Docker what to do.
Docker Daemon (dockerd)
The backstage crew 3 listens and does the real work.
Images
Like puppet blueprints (how to create a container).
Containers
Actual puppet shows (running apps).
Registry
Like an app store (Docker Hub) to download puppet blueprints (images).
Installing Docker on Windows
or Mac
By Ravi Kiran Maroju
Visit the Docker Website
Go to [Link]
Download Docker Desktop
Click the download button for your operating system
Install the Software
Run the installer just like any other software
Launch Docker
Open Docker and you're ready!
Installing Docker on Linux
(Ubuntu)
By Ravi Kiran Maroju
sudo apt update
sudo apt install [Link] -y
sudo systemctl enable docker
sudo systemctl start docker
Check it works:
docker --version
Docker Desktop vs Docker
Engine
By Ravi Kiran Maroju
Docker Desktop
GUI + Docker Engine (for Windows/Mac)
Docker Engine
The core part, runs in terminal (Linux)
Docker CLI vs Docker GUI
By Ravi Kiran Maroju
Interface What it is Example
CLI Command line tool docker ps
GUI Web interface with Portainer, Docker
buttons Desktop
Basic Docker Commands: Getting Started
By Ravi Kiran Maroju
Let's open a terminal or command prompt and try these!
Check Docker is working Run a container (example: hello-world)
docker version docker run hello-world
docker info
Basic Docker Commands:
Container Management
By Ravi Kiran Maroju
See running containers Stop a container
docker ps docker stop
Remove a stopped container
docker rm
Basic Docker Commands:
Container Interaction
By Ravi Kiran Maroju
Run a command inside container
docker exec -it bash
View logs from container
docker logs
Force kill a container
docker kill
Get full container details
docker inspect
Docker Container Tip
Use docker ps -a to see all containers (running and stopped)
By Ravi Kiran Maroju
Docker Images: Downloading
By Ravi Kiran Maroju
Remove an image
See your downloaded images docker rmi ubuntu
Pull an image from Docker Hub docker images
docker pull ubuntu
Creating a Custom Image from a Container
By Ravi Kiran Maroju
Create an image
Exit container, then get docker commit my-ubuntu-
Install something inside its container ID figlet
Start a container Example: apt install figlet docker ps -a
docker run -it ubuntu
Building from a Dockerfile:
Step 1
By Ravi Kiran Maroju
Create a file named Dockerfile:
FROM ubuntu
RUN apt update && apt install -y figlet
CMD ["figlet", "Hello Docker!"]
Building from a Dockerfile:
Steps 2-3
By Ravi Kiran Maroju
Build the image
docker build -t hello-docker .
Run it
docker run hello-docker
Lifecycle of a Docker Container
By Ravi Kiran Maroju
Create/Start Running
docker run docker ps
Removed Stopped
docker rm docker stop
Interacting with a Container
By Ravi Kiran Maroju
Start a shell inside
docker exec -it bash
Try something fun inside, like:
figlet Hello!
Foreground vs Detached
Mode
By Ravi Kiran Maroju
Mode Command Example What Happens
Foreground docker run ubuntu Stays open in
terminal
Detached (-d) docker run -d Runs in background
ubuntu sleep 1000 (silent mode)
Use docker ps to see detached containers.
Docker Volumes: Introduction
By Ravi Kiran Maroju
What are Volumes? Why Use Volumes?
Persistent data storage for Data persists even when
containers containers are removed
Data Sharing
Share data between containers
Creating and Managing
Docker Volumes
By Ravi Kiran Maroju
Create a volume
docker volume create my-vol
List volumes
docker volume ls
Inspect a volume
docker volume inspect my-vol
Remove a volume
docker volume rm my-vol
Using Volumes with
Containers
By Ravi Kiran Maroju
Mount a volume when Mount a host directory
running a container
docker run -v
docker run -v my-vol:/app /host/path:/container/path
nginx nginx
Read-only mount
docker run -v my-vol:/app:ro nginx
Docker Networks: Introduction
By Ravi Kiran Maroju
What are Docker Why Use Networks? Network Types
Networks? Isolation, security, and Bridge, host, overlay, macvlan,
Virtual networks that connect communication between and none
containers containers
Creating and Managing Docker Networks
By Ravi Kiran Maroju
Create a network
docker network create my-net
List networks
docker network ls
Inspect a network
docker network inspect my-net
Remove a network
docker network rm my-net
Using Networks with
Containers
By Ravi Kiran Maroju
Connect a container to a Connect a running
network container to a network
docker run --network=my- docker network connect my-
net nginx net container_id
Disconnect a container from a network
docker network disconnect my-net container_id
Docker Compose: Introduction
By Ravi Kiran Maroju
What is Docker Compose? Configuration Single Command
Tool for defining and running Uses YAML files to configure Create and start all services with
multi-container Docker application services one command
applications
Docker Compose: Basic
Commands
By Ravi Kiran Maroju
Start services
docker-compose up
Start in detached mode
docker-compose up -d
Stop services
docker-compose down
Rebuild services
docker-compose up --build
Docker Compose: Sample
YAML File
By Ravi Kiran Maroju
version: '3'
services:
web:
image: nginx
ports:
- "8080:80"
volumes:
- ./html:/usr/share/nginx/html
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: example
Docker Security: Best
Practices
By Ravi Kiran Maroju
Use Official Images
Always prefer official images from Docker Hub
Scan for Vulnerabilities
Use tools like Docker Security Scanning
Limit Container Resources
Set memory and CPU limits
Use Non-Root Users
Run containers with least privileges
Docker Security: Resource
Limits
By Ravi Kiran Maroju
Memory Limits CPU Limits
docker run --memory=512m docker run --cpus=0.5 nginx
nginx
Storage Limits
Use storage drivers with quotas
Docker in Production:
Orchestration
By Ravi Kiran Maroju
What is Orchestration? Popular Orchestration
Managing multiple containers Tools
across multiple hosts Kubernetes
Docker Swarm
Amazon ECS
Google Kubernetes Engine
(GKE)
Benefits
High availability
Scaling
Load balancing
Self-healing
Docker Swarm: Introduction
By Ravi Kiran Maroju
What is Docker Architecture
Swarm? Manager nodes and worker
Docker's native clustering nodes
and orchestration solution
Features
Load balancing, scaling, rolling updates, and service discovery
Docker Swarm: Basic
Commands
By Ravi Kiran Maroju
Initialize a swarm
docker swarm init
Join a swarm as a worker
docker swarm join --token :2377
List nodes
docker node ls
Deploy a service
docker service create --replicas 3 nginx
Kubernetes: Introduction
By Ravi Kiran Maroju
What is Kubernetes? Architecture
Open-source container Master node and worker
orchestration platform nodes
Components
Pods, services, deployments, and more
Kubernetes vs Docker Swarm
By Ravi Kiran Maroju
Feature Kubernetes Docker Swarm
Complexity Higher Lower
Scalability Excellent Good
Setup Time Longer Shorter
Auto-healing Advanced Basic
Community Very large Moderate
Docker Registry: Introduction
What is a Docker Docker Hub
Registry? Public registry provided by
Storage and distribution Docker
service for Docker images
Private Registry
Self-hosted or cloud-based private image storage
By Ravi Kiran Maroju
Working with Docker Registry
By Ravi Kiran Maroju
Login to Docker Hub
docker login
Tag an image
docker tag my-image username/my-image:tag
Push an image
docker push username/my-image:tag
Pull an image
docker pull username/my-image:tag
Setting Up a Private Docker
Registry
By Ravi Kiran Maroju
Run a registry container
docker run -d -p 5000:5000 --name registry registry:2
Tag an image for local registry
docker tag my-image localhost:5000/my-image
Push to local registry
docker push localhost:5000/my-image
Pull from local registry
docker pull localhost:5000/my-image
Docker Monitoring: Tools
By Ravi Kiran Maroju
Docker Prometheus Grafana
Stats Open-source Visualization
Built-in monitoring and analytics
command-line system platform
monitoring
cAdvisor
Container
resource usage
analyzer
Docker Stats: Basic
Monitoring
By Ravi Kiran Maroju
View stats for all View stats for specific
containers containers
docker stats docker stats container1
container2
Format output
docker stats --format "{{.Name}}: {{.CPUPerc}}"
Docker Logging:
Configuration
By Ravi Kiran Maroju
Default Logging Logging Drivers
json-file driver stores logs as syslog, journald, fluentd,
JSON awslogs, splunk, etc.
Configure at Runtime
docker run --log-driver=syslog nginx
Docker Logging: Commands
By Ravi Kiran Maroju
View container logs
docker logs container_id
Follow logs in real-time
docker logs -f container_id
Show timestamps
docker logs -t container_id
Limit output
docker logs --tail=100 container_id
Docker Networking: Types
By Ravi Kiran Maroju
Host
Bridge Removes network isolation, uses host's
Default network driver, isolated network networking directly
on a single host
1
Overlay
3 Connect multiple Docker daemons
across hosts
None
Macvlan
Disables networking for the container
Assign MAC addresses to containers,
appear as physical devices
Docker Port Mapping
By Ravi Kiran Maroju
Basic Port Mapping Multiple Port Mappings
docker run -p 8080:80 nginx docker run -p 8080:80 -p
443:443 nginx
Maps host port 8080 to
container port 80 Maps multiple ports
Random Host Port
docker run -p 80 nginx
Assigns a random host port
Docker Storage Drivers
By Ravi Kiran Maroju
What are Storage Available Drivers
Drivers? overlay2, aufs,
Control how images and devicemapper, btrfs, zfs, vfs
containers are stored and
managed on the host
Best Practice
Use overlay2 when possible (default on most systems)
Docker Multi-Stage Builds
By Ravi Kiran Maroju
Example Use Case
Benefits Compile code in one stage, copy only the
What are Multi-Stage Builds? Smaller final images, separation of build binary to the final image
Use multiple FROM statements in and runtime dependencies
Dockerfile to create smaller production
images
Docker Multi-Stage Build Example
By Ravi Kiran Maroju
# Build stage
FROM golang:1.16 AS builder
WORKDIR /app
COPY . .
RUN go build -o myapp
# Final stage
FROM alpine:3.14
WORKDIR /app
COPY --from=builder /app/myapp .
CMD ["./myapp"]
Docker Health Checks
By Ravi Kiran Maroju
What are Health Checks? In Dockerfile
Commands that check if a
container is healthy and HEALTHCHECK --
functioning properly interval=5m --timeout=3s \
CMD curl -f
[Link] || exit 1
At Runtime
docker run --health-cmd="curl -f [Link] || exit 1" \
--health-interval=5m nginx
Docker Environment Variables
By Ravi Kiran Maroju
In Dockerfile
1
ENV APP_HOME=/app
At Runtime
docker run -e "APP_HOME=/app" nginx
From File
3
docker run --env-file=[Link] nginx
View Environment Variables
docker exec container_id env
Docker Secrets
What are Docker Benefits
Secrets? Encrypted at rest, transmitted
Secure way to store sensitive over TLS, mounted as files in
data like passwords and API containers
keys
Availability
Only available in Docker Swarm mode
By Ravi Kiran Maroju
Managing Docker Secrets
By Ravi Kiran Maroju
Create a secret
docker secret create my_secret [Link]
List secrets
docker secret ls
Inspect a secret
docker secret inspect my_secret
Remove a secret
docker secret rm my_secret
Using Docker Secrets
By Ravi Kiran Maroju
With a service Access in container
Secrets are mounted at
docker service create \ /run/secrets/secret_name
--name nginx \
--secret my_secret \
cat /run/secrets/my_secret
nginx
With custom target
docker service create \
--name nginx \
--secret source=my_secret,target=[Link] \
nginx
Docker Content Trust
By Ravi Kiran Maroju
What is Content Trust? How it Works
Ensures the integrity and Uses digital signatures to
publisher of Docker images verify image authenticity
Enable Content Trust
export DOCKER_CONTENT_TRUST=1
Docker Bench Security
By Ravi Kiran Maroju
What is Docker Bench Security?
Script that checks for dozens of common best-practices around
deploying Docker containers in production
Running Docker Bench
docker run -it --net host --pid host --userns host --cap-add
audit_control \
-v /var/lib:/var/lib \
-v /var/run/[Link]:/var/run/[Link] \
-v /usr/lib/systemd:/usr/lib/systemd \
-v /etc:/etc --label docker_bench_security \
docker/docker-bench-security
Docker Performance Tuning
By Ravi Kiran Maroju
CPU Tuning Memory Tuning
Set CPU shares, quotas, and pinning Set memory limits and swappiness
Storage Tuning Network Tuning
Choose appropriate storage driver and mount options Optimize network driver and DNS settings
Docker Best Practices
By Ravi Kiran Maroju
Image Building Security
Use specific tags, not 'latest' Run as non-root
Minimize layers Scan for vulnerabilities
Use .dockerignore Use read-only filesystems
Multi-stage builds Limit capabilities
Operations
Use health checks
Set resource limits
Implement logging
Use Docker Compose
Docker Troubleshooting
By Ravi Kiran Maroju
Check container status
docker ps -a
View logs
2 docker logs container_id
Inspect container
docker inspect container_id
Debug with interactive shell
docker exec -it container_id sh
Common Docker Issues
By Ravi Kiran Maroju
Container Won't Start Image Pull Failures
Check logs: docker logs Verify network connectivity
container_id Check authentication
Verify port availability Confirm image name and
Check resource constraints tag
Volume Mount Issues
Verify paths exist
Check permissions
Inspect volume: docker volume inspect volume_name
Docker Community
Resources
By Ravi Kiran Maroju
Documentation Forums GitHub
[Link] [Link] [Link]/docker
Slack
Docker Community
Slack
Docker Learning Path
By Ravi Kiran Maroju
Beginner
Learn basic commands and concepts
Intermediate
Create custom images and multi-container applications
Advanced
Orchestration, security, and production deployment
Expert
Performance tuning, custom plugins, and contributing to
Docker