Privacy Policy
© 2025 linux101.dev

Docker Containers Cheatsheet

A container is a runnable instance of a Docker image. Here are the most common commands for managing the lifecycle of your containers.

Container Lifecycle Commands

CommandDescription
docker run [IMAGE]Creates and starts a new container from an image. This is the first step to get a container running.
docker psLists all running containers. Use docker ps -a to see all containers, including stopped ones.
docker start [CONTAINER_ID or NAME]Starts a stopped container.
docker stop [CONTAINER_ID or NAME]Gracefully stops a running container. Docker will send a SIGTERM signal to the main process and then a SIGKILL after a timeout.
docker restart [CONTAINER_ID or NAME]Restarts a running container.
docker rm [CONTAINER_ID or NAME]Removes a stopped container from the system. You must stop a container before you can remove it.
docker exec -it [CONTAINER_ID or NAME] [COMMAND]Executes a command inside a running container. The -it flags are commonly used to create an interactive terminal session (e.g., docker exec -it my-container bash).
docker container pruneRemoves all stopped containers. This is a quick way to clean up your system.