Docker Cheatsheet
Essential Docker commands and options for container management
Useful Docker Resources
Basic Commands
docker --version
Show the Docker version
docker info
Display system-wide information
docker run <image>
Run a command in a new container
docker pull <image>
Pull an image from a registry
docker images
List all local images
docker ps
List running containers
docker ps -a
List all containers (running and stopped)
Container Management
docker start <container>
Start a stopped container
docker stop <container>
Stop a running container gracefully
docker restart <container>
Restart a container
docker kill <container>
Force stop a container
docker rm <container>
Remove a container
docker rm -f <container>
Force remove a running container
docker container prune
Remove all stopped containers
Image Management
docker rmi <image>
Remove an image
docker build -t <name:tag> .
Build an image from a Dockerfile
docker tag <image> <name:tag>
Tag an image
docker push <name:tag>
Push an image to a registry
docker image prune
Remove unused images
docker image prune -a
Remove all unused images
docker save -o <file.tar> <image>
Save an image to a tar archive
Container Interaction
docker exec -it <container> <command>
Run a command in a running container
docker exec -it <container> bash
Get a bash shell in a running container
docker attach <container>
Attach to a running container
docker logs <container>
Fetch the logs of a container
docker logs -f <container>
Follow the logs of a container
docker cp <container>:<path> <host_path>
Copy files from container to host
docker cp <host_path> <container>:<path>
Copy files from host to container
Docker Compose
docker-compose up
Create and start containers as defined in docker-compose.yml
docker-compose up -d
Create and start containers in detached mode
docker-compose down
Stop and remove containers, networks, images, and volumes
docker-compose ps
List containers in the compose setup
docker-compose logs
View output from containers
docker-compose build
Build or rebuild services
docker-compose restart
Restart all services
Network & Volume
docker network ls
List networks
docker network create <name>
Create a network
docker network connect <network> <container>
Connect a container to a network
docker network rm <network>
Remove a network
docker volume ls
List volumes
docker volume create <name>
Create a volume
docker volume rm <volume>
Remove a volume