Container State Management in Docker

From the Docker cheat sheet · Container Management · verified Jul 2026

Container State Management

Control container lifecycle - start, stop, restart, and remove

bash
# List containers
docker ps                    # Running only
docker ps -a                 # All containers
docker ps -q                 # Only IDs

# Start/Stop/Restart
docker start container_name
docker stop container_name
docker restart container_name

# Remove containers
docker rm container_name
docker rm -f container_name  # Force remove

# Clean up
docker container prune       # Remove stopped
💡 docker ps -a shows stopped containers too
⚠️ Use -f flag carefully to force remove
📌 Container prune removes all stopped containers
✅ Always stop before removing unless using -f

More Docker tasks

Back to the full Docker cheat sheet