A comprehensive guide to Docker that takes you from complete beginner to upper intermediate level, with practical examples and clear explanations of what problems each concept solves.
Docker is a platform that allows you to package applications and their dependencies into containers. These containers can run consistently across different environments, from your local machine to production servers.
- "It works on my machine" - Applications behave differently across environments
- Complex setup processes for new developers joining a project
- Dependency conflicts between different projects on the same machine
- Difficult to replicate production environments locally
- Time-consuming deployment processes
- Consistent environments everywhere (development, testing, production)
- New developers can get started in minutes with a single command
- Each project runs in isolation with its own dependencies
- Production environment can be replicated exactly on your laptop
- Simplified and standardized deployment process
Virtual machines include a full operating system, which makes them heavy and slow to start. Docker containers share the host operating system kernel, making them lightweight and fast.
| Types | Virtual Machine | Docker Container |
|---|---|---|
| Size | Minutes | Megabytes |
| Startup time | More | Seconds |
| Resource usage | High | Low |
| Isolation | Complete | Process-level |
Download and install Docker Desktop from the official website:
- Install the .dmg/.exe file
- Start Docker Desktop from Applications
Verify installation:
docker --version
# Output: Docker version 29.0.0, build 3d4129b
docker compose version
# Output: Docker Compose version v2.40.3Follow the installation instructions from the official website based on your Linux distribution.
Verify installation
sudo docker --version
# Output: Docker version 29.0.0, build 3d4129bAdd your user to the docker group to run Docker without sudo:
sudo usermod -aG docker $USER
# Log out and log back in for this to take effectRun this command to verify everything is working:
docker run hello-worldThis command downloads a test image and runs it in a container. If you see a "Hello from Docker!" message, your installation is successful.
These are the most essential topics you need to understand before diving into the commands:
- A Docker image is a read-only template that contains the application code, runtime, libraries, and dependencies needed to run an application.
- Think of an image as a recipe or a blueprint. It describes what should be in the container, but it isn't running anything yet.
- Images ensure that everyone uses the exact same environment. When you share an image, you're sharing the complete setup, not just instructions that might be interpreted differently.
Example:
# The nginx:1.29.3 image contains:
# - Nginx web server version 1.29.3
# - All required libraries
# - Default configuration
# - Linux base system- A container is a running instance of an image. It's an isolated process that runs on your host machine.
- If an image is a recipe, a container is the actual dish you've cooked. You can create many containers (dishes) from one image (recipe).
- Containers provide isolation, so multiple applications can run on the same machine without interfering with each other.
Example:
# You can run multiple containers independently from the same nginx image
docker run -d -p 8080:80 --name web1 nginx:1.29.3
docker run -d -p 8081:80 --name web2 nginx:1.25- A text file containing instructions to build a Docker image.
- Instead of manually configuring a system, you write the steps in a Dockerfile. This makes your setup reproducible and version-controlled.
Example:
FROM node:24-alpine
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
CMD ["node", "server.js"]- A tool for defining and running multi-container applications using a YAML file.
- Real applications often need multiple services (web server, database, cache). Docker Compose lets you start them all with one command and ensures they can communicate.
Example:
services:
web:
build: .
ports:
- "3000:3000"
database:
image: postgres:15- A cloud-based registry where you can find and share Docker images.
- Instead of building everything from scratch, you can use official images maintained by organizations. For example, you don't need to figure out how to install Node.js in a container - just use the official Node.js image.
- A mechanism for persisting data generated by and used by Docker containers.
- Containers are temporary. When you delete a container, all data inside it is lost. Volumes store data outside the container so it persists.
Introduction | Basic Commands | Containers | Docker Compose | Dockerfile | Networking | Volumes | Best Practice
This is a living document! Contributions are welcome:
- Fork the repository
- Create a feature branch
- Make your improvements
- Submit a pull request
Areas for contribution:
- Additional real-world examples
- More troubleshooting scenarios
- Advanced topics (Kubernetes, Swarm, etc.)
- Platform-specific guides
- Video tutorials or diagrams
- Docker Getting Started Tutorial
- Play with Docker - Browser-based Docker playground
- Docker Desktop
- Portainer - Container management UI
- Dive - Explore image layers
- Hadolint - Dockerfile linter
This cheatsheet is released under the MIT License. Feel free to use, modify, and distribute it.
Maintained with ❤️ by Reajul Hasan Raju