Docker Cheatsheet
Essential Docker commands and options for container management
Useful Docker Resources
Basic Commands
docker --versionShow the Docker version
docker infoDisplay system-wide information
docker run <image>Run a command in a new container
docker pull <image>Pull an image from a registry
docker imagesList all local images
docker psList running containers
docker ps -aList 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 pruneRemove 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 pruneRemove unused images
docker image prune -aRemove 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> bashGet 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 upCreate and start containers as defined in docker-compose.yml
docker-compose up -dCreate and start containers in detached mode
docker-compose downStop and remove containers, networks, images, and volumes
docker-compose psList containers in the compose setup
docker-compose logsView output from containers
docker-compose buildBuild or rebuild services
docker-compose restartRestart all services
Network & Volume
docker network lsList 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 lsList volumes
docker volume create <name>Create a volume
docker volume rm <volume>Remove a volume