Docker Cheatsheet

A quick reference for common Docker and Docker Compose commands.

Container Management

Command Description
docker run [image] Create and start a new container from an image.
docker run -d -p [host_port]:[container_port] [image] Run a container in detached mode with port mapping.
docker ps List all running containers.
docker ps -a List all containers (running and stopped).
docker stop [container_id] Stop a running container.
docker start [container_id] Start a stopped container.
docker rm [container_id] Remove a stopped container.
docker logs [container_id] Fetch the logs of a container.
docker exec -it [container_id] [command] Execute a command inside a running container (e.g., /bin/bash).

Docker Compose

Command Description
docker-compose up Create and start containers defined in docker-compose.yml.
docker-compose up -d Create and start containers in detached mode.
docker-compose down Stop and remove containers, networks, and volumes.
docker-compose ps List containers for the current project.
docker-compose logs -f [service_name] Follow log output for a specific service.

Image Management

Command Description
docker build -t [name:tag] . Build an image from a Dockerfile in the current directory.
docker images List all local images.
docker rmi [image_id] Remove a local image.
docker pull [image] Pull an image from a registry (e.g., Docker Hub).
docker push [username/image] Push an image to a registry.

System

Command Description
docker system prune Remove all unused containers, networks, images (both dangling and unreferenced).
docker system prune -a Remove all unused images, not just dangling ones.
docker info Display system-wide information.

© 2025 devcortex.ai ・ AI-powered developer tools.