Essential Docker CLI Commands
Learn the everyday CLI commands used by DevOps engineers to launch, monitor, inspect, and manage running containers.
1. Container Management Commands Reference
| Command | Description | Example Usage |
|---|---|---|
docker run | Pulls image if needed & creates/starts container | docker run -d -p 8080:80 nginx |
docker ps | Lists active running containers (`-a` for all) | docker ps -a |
docker stop | Gracefully stops a running container | docker stop my-container |
docker start | Starts a stopped container | docker start my-container |
docker rm | Deletes a stopped container (`-f` to force) | docker rm -f my-container |
docker logs | Fetches container console stdout logs (`-f` to stream) | docker logs -f my-container |
docker exec | Executes a command inside a running container | docker exec -it my-container bash |
2. Live Command Workflows
A. Running an Nginx Web Server in Background (`-d`) with Port Mapping (`-p 8080:80`):
docker run -d --name my-webserver -p 8080:80 nginx:latest
B. Opening an Interactive Shell Inside Container (`-it`):
docker exec -it my-webserver /bin/bash
C. Tail Container Logs in Real-time (`-f`):
docker logs -f --tail 100 my-webserver
Next Up
Learn how to search, pull, list, tag, and inspect Docker Images on Docker Hub.
Next Lesson: Working with Docker Images →