List containers
Show the running containers:
docker ps

Show all containers, including stopped ones:
sudo docker ps -a

Show only the container IDs:
sudo docker ps -aq

You can filter the list, for example docker ps --filter "status=exited".
Start a container
Start an existing, stopped container:
docker start <container_id_or_name>

Create and start a new container from an image:
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Example, with a name:
docker run --name=Ubuntu_Docker ubuntu:22.04
Useful options: -d runs it in the background, -p 8080:80 publishes a port, and -it opens an interactive terminal.
Stop a container
docker stop <container_id_or_name>

docker stop sends a stop signal and waits 10 seconds before it kills the container. Change the wait time:
docker stop --time=20 <container_id>
Force it to stop at once:
docker kill <container_id>
Stop all running containers:
docker stop $(docker ps -q)
Restart a container:
docker restart <container_id>
Remove a stopped container:
docker rm <container_id>
Why manage containers well
- Free CPU, memory and disk on the server.
- Keep the system tidy and easy to debug.
- Avoid conflicts between ports and names.
- Improve security by stopping what you do not use.
FAQ
What is Docker? A platform that packs apps and their dependencies in containers.
How do I list containers? docker ps for running ones, docker ps -a for all.
How do I start a container? docker start NAME for an existing one, docker run IMAGE for a new one.
How do I stop a container? docker stop NAME.
Quick recap
docker ps -a,docker start,docker stop.