Docker Cheatsheet

Command Description
docker version Show the Docker version information
docker info Show system-wide information about Docker
docker pull <image_name> Pull an image from Docker Hub
docker images List all local images
docker run <image_name> Run a container from an image
docker ps List all running containers
docker ps -a List all containers (running and stopped)
docker start <container_id> Start a stopped container
docker stop <container_id> Stop a running container
docker rm <container_id> Remove a container
docker rmi <image_id> Remove an image
docker exec -it <container_id> bash Run a command inside a running container
docker build -t <image_name> . Build an image from a Dockerfile
docker-compose up Start services defined in a Compose file
docker-compose down Stop and remove containers created by ‘up’
docker-compose ps List services
docker-compose logs Show logs for all services
docker-compose exec <service_name> <command> Execute a command in a running service container
Docker Containers Cheatsheet

Docker Containers Cheatsheet

Command Description
docker ps List all running containers
docker ps -a List all containers (running and stopped)
docker start <container_id> Start a stopped container
docker stop <container_id> Stop a running container
docker restart <container_id> Restart a running container
docker rm <container_id> Remove a stopped container
docker rm $(docker ps -a -q) Remove all stopped containers
docker rm -f <container_id> Forcefully remove a running container
docker logs <container_id> Show logs of a container
docker inspect <container_id> Show low-level information about a container
docker exec -it <container_id> bash Run a command inside a running container
docker cp <container_id>:/path/to/container/file /host/path Copy files/folders between a container and host
docker stats Show resource usage statistics of running containers
Docker Compose Cheatsheet

Docker Compose Cheatsheet

Command Description
docker-compose up Start services defined in a Compose file
docker-compose up -d Start services in detached mode (in the background)
docker-compose down Stop and remove containers created by ‘up’
docker-compose down -v Remove volumes along with containers
docker-compose ps List services
docker-compose logs Show logs for all services
docker-compose logs <service_name> Show logs for a specific service
docker-compose exec <service_name> <command> Execute a command in a running service container
docker-compose build Build or rebuild services
docker-compose restart <service_name> Restart a service
docker-compose pause <service_name> Pause a service
docker-compose unpause <service_name> Unpause a service
docker-compose scale <service_name>=<num_containers> Scale a service to a specific number of containers