Essential Docker Commands
| Category | Command | Description |
|---|---|---|
| System | docker version | Displays installed Docker version |
| System | sudo systemctl status docker | Check Docker daemon status (Linux) |
| Images | docker images | List 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 |
| Images | docker pull <image>:<tag> | Download image from registry. tag is optional, if not specified, latest is pulled |
| Images | docker rmi <image> | Remove a specific image |
| Images | docker image prune -a | Clean up all unused images |
| Containers | docker run <image> | Create and start a new container |
| Containers | docker ps -a | List all containers (running & stopped) |
| Containers | docker stop <id> | Stop a running container gracefully |
| Containers | docker start <id> | Start a stopped container |
| Containers | docker rm <id> | Remove a stopped container |
| Containers | docker container prune | Delete all stopped containers |
| Execution | docker exec -it <id> bash | Run interactive shell in container |
| Logs | docker logs <id> | Show container logs |
| Logs | docker logs -f <id> | Follow logs in real-time |
Critical Flags & Modifiers
| Flag | Category | Purpose |
|---|---|---|
-d | Execution | Detached: Run in background |
-p | Networking | Publish: Map host to container ports (e.g., -p 8080:80) |
-it | Interaction | Interactive: Enable terminal interaction |
-f | Logs/Rm | Follow/Force: Stream logs or force remove |
--tail | Logs | Limit output to last N lines |
--name | Identity | Assign custom container name |
--rm | Cleanup | Auto-remove container on exit |
-a | Cleanup | All: Remove all unused assets |