Docker Cheatsheet for Beginners
This cheatsheet is a reference for Docker beginners who want to quickly get started running and inspecting containers. For a comprehensive introduction to Docker, read the Docker overview guide and complete the Getting Started with Docker tutorial.
About Docker
Docker is a platform for developing, shipping, and running applications. It allows you to package and run applications in isolated environments called containers. Docker containers are created from read-only templates called images. Docker images are hosted in registries, such as Docker Hub.
Basic Commands
Running and Inspecting Containers
Pull an image from a registry:
$ docker pull <image>
List local images:
$ docker images
Run a container:
$ docker run <container>
Run a container in the background:
$ docker run -d <container>
List currently running containers:
$ docker ps
List all containers:
$ docker ps -a
List currently running containers and their resource usage statistics:
$ docker stats
Show a container’s logs:
$ docker logs <container>
Show a container’s metadata:
$ docker inspect <container>
Stop a container:
$ docker stop <container>
Cleaning up stopped containers and unused images
Remove a stopped container’s metadata:
$ docker rm <container>
Remove the metadata of all stopped containers:
$ docker container prune -f
Remove an image:
$ docker rmi <image>
Remove all unused images:
$ docker image prune --all