Docker Cheat Sheet
In this article, we will showcase the six most practical Docker commands that one continually needs in daily Docker dealings.
Please note that this is, of course, not a complete list of all possible commands but serves as a short reference list of the most important ones.
6 Practical Docker Commands
List All Running Containers
With docker ps, you can list all running containers and get an overview of the names and IDs. From here, you can execute additional commands like logs, stop, or kill.
Display Stats of the Running Containers
docker stats list all running containers in a manner similar to ps and displays their current resource consumption.
Open SSH in a Container
To open shell session in a running Docker container, you can use the exec command: docker exec -it <container name> /bin/sh. However, ensure that the necessary binaries are present as many bootstrap base container images are trimmed to an absolute minimum.
Delete All Images, Containers, and Networks
A command to clean up everything on the local development machine is docker system prune -af. Naturally, this command should be used with caution.
Stopping a Container Hard
The stop command sends a SIGTERM. If this is not sufficient or not fast enough, a container can be abruptly stopped with docker kill via SIGKILL.
Display Logs of a Container
A command that every Docker user encounters multiple times daily is docker logs <container name> which output the log lines of the container. Another commonly used option is docker logs --follow <container name> to keep the log stream open.
Additional Information
A more extensive official cheat sheet for Docker commands can also be found at the Official Docker Cheat Sheet.