Essential Docker Commands

CategoryCommandDescription
Systemdocker versionDisplays installed Docker version
Systemsudo systemctl status dockerCheck Docker daemon status (Linux)
Imagesdocker imagesList all downloaded images.
Displays REPOSITORY, TAG, IMAGE ID, CREATED, SIZE i.e
Image name, Version of the image, Unique identifier, Time since creation, Image size
Imagesdocker pull <image>:<tag>Download image from registry. tag is optional, if not specified, latest is pulled
Imagesdocker rmi <image>Remove a specific image
Imagesdocker image prune -aClean up all unused images
Containersdocker run <image>Create and start a new container
Containersdocker ps -aList all containers (running & stopped)
Containersdocker stop <id>Stop a running container gracefully
Containersdocker start <id>Start a stopped container
Containersdocker rm <id>Remove a stopped container
Containersdocker container pruneDelete all stopped containers
Executiondocker exec -it <id> bashRun interactive shell in container
Logsdocker logs <id>Show container logs
Logsdocker logs -f <id>Follow logs in real-time

Critical Flags & Modifiers

FlagCategoryPurpose
-dExecutionDetached: Run in background
-pNetworkingPublish: Map host to container ports (e.g., -p 8080:80)
-itInteractionInteractive: Enable terminal interaction
-fLogs/RmFollow/Force: Stream logs or force remove
--tailLogsLimit output to last N lines
--nameIdentityAssign custom container name
--rmCleanupAuto-remove container on exit
-aCleanupAll: Remove all unused assets