Docker Revision ( 1 Page)
๐ณ Docker Cheatsheet โ Quick Revision
๐น Basics
What is Docker?
Platform to build, ship, and run applications in containers (lightweight, isolated environments).Key Components:
Image โ Blueprint (read-only).
Container โ Running instance of an image.
Dockerfile โ Instructions to build an image.
Registry โ Store/distribute images (e.g., Docker Hub).
๐น Common Commands
| Action | Command |
| Check version | docker --version |
| List images | docker images |
| List containers (running/all) | docker ps / docker ps -a |
| Pull image | docker pull nginx:latest |
| Run container | docker run -d -p 8080:80 nginx |
| Stop container | docker stop <container_id> |
| Remove container | docker rm <container_id> |
| Remove image | docker rmi <image_id> |
| Logs | docker logs <container_id> |
| Exec inside container | docker exec -it <id> bash |
๐น Dockerfile Essentials
FROM ubuntu:20.04 # Base image
WORKDIR /app # Set working dir
COPY . /app # Copy files
RUN apt-get update && apt-get install -y python3
CMD ["python3", "app.py"] # Default command
๐ Build: docker build -t myapp .
๐ Run: docker run -d myapp
๐น Networking & Volumes
Ports:
docker run -p 8080:80 nginxโ Host:8080 โ Container:80Volumes (persistent data):
docker run -v /host/data:/container/data mysql
Read-only volume:
docker run -v /host/data:/container/data:ro nginx
๐น Docker Compose
- Define multi-container apps (
docker-compose.yml):
version: '3'
services:
web:
image: nginx
ports:
- "8080:80"
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: root
๐ Run: docker-compose up -d
๐น Best Practices
Use .dockerignore to avoid copying unnecessary files.
Use multi-stage builds for smaller images.
Keep containers stateless โ use volumes for data.
Tag images (
myapp:v1) instead of usinglatest.
โก๏ธ Quick Tip: Containers are ephemeral. Always use volumes for persistence.

