Docker Cheatsheet
Docker Cheatsheet
Docker Basics
Docker Installation
Basic Commands
# Remove a container
docker rm <container_id>
# Remove an image
docker rmi <image_name>
Real-Life Example
Docker Compose
Docker Compose is a tool for defining and running multi-container Docker applications.
version: '3'
services:
web:
image: nginx
ports:
- "8080:80"
db:
image: postgres
environment:
POSTGRES_PASSWORD: example
# Stop services
docker-compose down
# View service logs
docker-compose logs
Real-Life Example
docker-compose up
This will start both an Nginx web server and a PostgreSQL database.
Docker Networking
Docker networking allows containers to communicate with each other, either on the same
host or across different hosts.
# List networks
docker network ls
# Create a network
docker network create <network_name>
Real-Life Example
# Create a network
docker network create my_network
Docker Images
A Docker image is a read-only template with instructions for creating a Docker container.
Managing Images
# Tag an image
docker tag <image_id> <repository>/<image_name>:<tag>
# Remove an image
docker rmi <image_name>
Real-Life Example
FROM ubuntu:latest
RUN apt-get update && apt-get install -y nginx
CMD ["nginx", "-g", "daemon off;"]
A Docker container is a runnable instance of an image. You can create, start, stop, move,
or delete a container using Docker commands.
# Run a container
docker run -d --name <container_name> <image_name>
# Restart a container
docker restart <container_id>
Real-Life Example
With this cheat sheet, you should have a foundational understanding of Docker and its
core components, enabling you to streamline your DevOps workflows effectively.