Quick Reference

Cheatsheets

Practical command references for Linux, networking, servers, containers, databases, and more.

Cheatsheet#docker-cheatsheet

Docker Cheatsheet

Docker is a platform for developing, shipping, and running applications in isolated environments called containers.

Image Management

docker images                  # List all local images
docker pull ubuntu:latest      # Download an image from Docker Hub
docker rmi ubuntu:latest       # Delete a local image
docker build -t myapp:1.0 .    # Build an image from a Dockerfile in the current directory
docker history myapp:1.0       # Show the history of an image

Container Management

docker ps                      # List running containers
docker ps -a                   # List all containers (running and stopped)
docker run -d --name web nginx # Run a container in the background (detached)
docker run -it ubuntu bash     # Run an interactive container and attach to its bash shell
docker stop web                # Gracefully stop a container
docker start web               # Start a stopped container
docker rm web                  # Delete a stopped container
docker rm -f web               # Force delete a running container

Port Forwarding and Volumes

# Map host port 8080 to container port 80
docker run -d -p 8080:80 nginx
 
# Mount a host directory to a container directory
docker run -d -v /host/path:/container/path nginx
 
# Use a named volume (Docker manages the storage location)
docker run -d -v myvolume:/var/lib/mysql mysql

Logs and Debugging

docker logs web                # View container logs
docker logs -f web             # Follow container logs in real-time
docker inspect web             # Show detailed container configuration in JSON
docker exec -it web sh         # Execute a shell inside a running container
docker top web                 # Show running processes inside a container

System Cleanup

docker system prune            # Remove unused data (stopped containers, dangling images, unused networks)
docker system prune -a         # Remove ALL unused images, not just dangling ones
docker system prune --volumes  # Remove unused volumes as well