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

CommandDescriptionExample Usage
docker runPulls image if needed & creates/starts containerdocker run -d -p 8080:80 nginx
docker psLists active running containers (`-a` for all)docker ps -a
docker stopGracefully stops a running containerdocker stop my-container
docker startStarts a stopped containerdocker start my-container
docker rmDeletes a stopped container (`-f` to force)docker rm -f my-container
docker logsFetches container console stdout logs (`-f` to stream)docker logs -f my-container
docker execExecutes a command inside a running containerdocker 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 →