This list categorizes essential Docker commands for managing containers, images, networks, volumes, and services efficiently.
1. System Cleanup & Information
docker system prune -a removes all unused data, including images, containers, and networks.
docker system df -v displays detailed disk usage.
docker info --format outputs system information in a formatted manner.
2. Container Management
docker run -it image bash starts a container in interactive mode with a bash shell.
docker run --rm -v $(pwd):/app -w /app image command runs a command inside a mounted volume.
docker run -d image runs a container in detached mode.
docker ps -f "status=exited" lists stopped containers.
docker inspect container --format='{{.State.ExitCode}}' retrieves a container’s exit code.
3. Image Building & Management
docker build -t image-name . builds an image from a Dockerfile in the current directory.
docker build --no-cache=true disables build cache to force a fresh build.
docker history --no-trunc image shows the complete history of an image.
4. Networking & Connectivity
docker network create network-name creates a new network.
docker network inspect network-name provides details about a network.
docker network connect --alias alias network container assigns an alias to a container in a specific network.
docker network rm network-name removes a custom Docker network.
5. Volumes & File Sharing
docker volume prune --force removes all unused volumes without confirmation.
docker run --rm -v host-path:container-path image mounts a volume to share files between host and container.
--mount type=bind,source=hostpath,target=container-path specifies a bind mount for file sharing.
6. Environment Variables & Resource Allocation
docker run -e KEY=value image sets an environment variable in a container.
docker run --cpu-shares value image allocates CPU shares to a container.
docker run --memory-swap value image defines memory limits, including swap space.
7. Security & User Management
docker run -u username image runs a container with a specified user.
--security-opt configures security options for a container.
--cap-add and --cap-drop add or remove Linux capabilities from a container.
8. Docker Compose & Multi-Stage Builds
docker-compose -f file -f override-file up allows multiple Compose files to configure services.
FROM base-image AS stage-name defines a build stage in a multi-stage Dockerfile.
COMPOSE_PROJECT_NAME specifies a project name for Docker Compose.
9. Logging & Monitoring
docker logs -f container streams live logs from a running container.
docker events retrieves a real-time stream of events from the Docker server.
docker inspect container --format='{{.State.Health.Status}}' fetches the health status of a container.
10. Swarm & Service Management
docker service scale service=replicas adjusts the number of replicas for a service.
docker service logs service displays logs for a specific service in a Swarm cluster.
docker service update --health-cmd command service updates the health check command for a service.
11. Container Startup & Execution Options
docker run --restart always image ensures a container restarts unless explicitly stopped.
--entrypoint overrides the default entry point of an image when running a container.
docker exec -it container sh starts a shell session inside a running container.
12. System Utilities & Versioning
docker --version displays the installed Docker version.
docker version provides version details for both the client and server.
docker command --help shows detailed help for a specific Docker command.
This summary covers key Docker functionalities to optimize containerized application deployment, management, and troubleshooting. 🚀
Watch video Master Docker Essentials: Top Commands for DevOps Interview Preparation Part 3 online without registration, duration hours minute second in high quality. This video was added by user Open Source Devops 25 January 2025, don't forget to share it with your friends and acquaintances, it has been viewed on our site 24 once and liked it 0 people.