Docker Cheatsheet
A complete student-friendly guide to Docker. Learn how to run, manage, and build containers with practical examples.
What is Docker?
Docker is a platform that lets you package applications and their dependencies into containers. Containers run consistently across different environments — your laptop, servers, or the cloud.
Images
Images are blueprints for containers. You can pull them from Docker Hub or build your own with a Dockerfile.
docker pull ubuntu
docker images
docker rmi ubuntu
Containers
Containers are running instances of images. You can start, stop, and remove them easily.
docker run ubuntu echo "Hello Docker"
docker ps
docker stop container_id
docker rm container_id
Interactive Mode
Use -it
to run containers interactively. --rm
automatically removes the container after exit.
docker run -it ubuntu bash
docker run --rm ubuntu echo "Temporary Container"
Ports & Volumes
Expose ports with -p
and persist data using -v
(volumes).
docker run -p 8080:80 nginx
docker run -v /host/data:/container/data ubuntu
Dockerfile Basics
A Dockerfile defines how to build a custom image. Common commands include FROM
, COPY
, RUN
, CMD
, and WORKDIR
.
FROM node:18
WORKDIR /app
COPY . .
RUN npm install
CMD ["node", "index.js"]
Build & Run Custom Images
Use docker build
to create an image and docker run
to start it.
docker build -t myapp .
docker run -p 3000:3000 myapp
Docker Compose
Docker Compose manages multi-container applications with a YAML file. Perfect for apps with databases + backend + frontend.
# docker-compose.yml
version: "3"
services:
web:
build: .
ports:
- "3000:3000"
db:
image: mongo
Logs & Exec
View container logs or open a shell inside a running container.
docker logs container_id
docker exec -it container_id bash
Networks
Networks let containers talk to each other. Docker creates a default bridge, but you can also define custom networks.
docker network ls
docker network create mynetwork
docker run --network=mynetwork myapp
Cleanup
Free up space by removing stopped containers, unused images, and networks with prune commands.
docker system prune
docker volume prune
Best Practices
Use smaller base images (like alpine
), add a .dockerignore
file to skip unnecessary files, and keep containers single-purpose for efficiency.
How to use this page
- Start with images and containers basics.
- Learn Dockerfile and build your own images.
- Practice Compose for multi-service apps.
- Explore networks, volumes, and cleanup commands.
🚀 Explore More Free Developer Tools
Don’t stop here! Supercharge your workflow with our other powerful converters & formatters.
📚 Linux Cheatsheet
Linux Cheatsheet
📚 MongoDB Cheatsheet
MongoDB Cheatsheet
📚 Git Cheatsheet
Git Cheatsheet
💡 New tools are added regularly — bookmark DevUtilsX and stay ahead!
Want to support my work?
Buy me a coffee