Docker Config Reference (docker system / docker tag / docker top)
We go over numerous examples of using docker system / docker tag and docker top!
Examples of the Docker System Command
The docker system command provides utilities for managing Docker's system-wide resources and information, including disk usage, pruning unused data, viewing events, and retrieving system details. It is particularly useful for maintenance, monitoring, and optimization in both single-host and Swarm environments.
docker system df
This command displays a detailed breakdown of Docker's disk usage, categorizing consumption by images, containers, volumes, and build cache. It reports sizes in a human-readable format, enabling administrators to identify resource-heavy components and plan cleanup operations to reclaim storage space efficiently.
docker system prune
This command removes all unused Docker objects, including stopped containers, dangling images, unused networks, and build cache, but prompts for confirmation. It helps in freeing significant disk space by eliminating orphaned resources, which is essential for maintaining system performance in long-running environments.
docker system info
This command outputs comprehensive information about the Docker installation, including server version, operating system, kernel details, storage driver, and Swarm status. It serves as a diagnostic tool for verifying configurations, compatibility, and runtime environment specifics during troubleshooting or audits.
docker system events
This command streams real-time events from the Docker daemon, such as container starts, stops, or image pulls, in a continuous log format. It facilitates monitoring system activity, which is valuable for logging integrations or detecting anomalies in operational workflows.
docker system prune --all
With the --all flag, this command extends pruning to include all unused images (not just dangling ones), in addition to containers, networks, and volumes. It provides a more thorough cleanup, ideal for resetting development environments while requiring caution to avoid removing referenced resources.
docker system df --verbose
Using the --verbose flag, this command provides an extended disk usage report, including breakdowns per image, container, or volume. It offers granular insights into space allocation, assisting in pinpointing specific items for targeted removal or optimization.
docker system prune --force
The --force flag executes pruning without confirmation prompts, removing unused containers, images, networks, and volumes. It is suited for automated scripts in CI/CD pipelines, ensuring non-interactive resource management while risking accidental data loss if misapplied.
docker system events --filter type=container
This command streams events filtered to only container-related activities, such as create, start, or die events. It narrows monitoring to specific subsystems, enhancing efficiency in large-scale deployments where focused logging is required.
docker system prune --volumes
This command specifically prunes unused volumes in addition to default objects like containers and images. It targets persistent storage cleanup, which is critical for preventing disk exhaustion in applications with high data turnover.
docker system info --format "{{json .}}"
With the --format flag using a JSON template, this command outputs system information in structured JSON format. It enables programmatic parsing for integration with monitoring tools or scripts, providing detailed, machine-readable data on Docker's configuration and status.
Examples of the Docker Tag Command
The docker tag command assigns a new reference (name and tag) to an existing image, allowing for versioning, repository organization, or preparation for pushing to registries. It does not create a new image but adds an alias, facilitating image management without duplication.
docker tag nginx:latest myrepo/nginx:v1.0
This command tags the existing "nginx:latest" image with a new reference "myrepo/nginx:v1.0". It prepares the image for pushing to a custom repository, enabling version-specific deployments while maintaining the original tag for reference.
docker tag ubuntu:20.04 ubuntu:focal
This command assigns an additional tag "ubuntu:focal" to the "ubuntu:20.04" image. It creates a human-readable alias for the LTS version, simplifying selection in build scripts or deployments without altering the image content.
docker tag mysql:8.0 registry.example.com/db/mysql:prod
This command tags "mysql:8.0" with "registry.example.com/db/mysql:prod" for a private registry. It organizes images for enterprise distribution, ensuring the production-ready database image is distinctly referenced.
docker tag golang:1.21 mygolang:dev
This command tags "golang:1.21" as "mygolang:dev". It customizes naming for development workflows, allowing easy switching between toolchains without pulling new images.
docker tag redis:latest redis:stable
This command adds the tag "redis:stable" to "redis:latest". It denotes a reliable version for caching services, supporting rollback strategies in production environments.
docker tag alpine:3.18 base/alpine:latest
This command tags "alpine:3.18" with "base/alpine:latest". It categorizes the lightweight base image under a namespace, facilitating organized use in multi-stage builds.
docker tag busybox busybox:test
This command tags the "busybox" image (default latest) as "busybox:test". It prepares a utility image for testing scenarios, allowing isolated experimentation without affecting the primary reference.
docker tag customimage:1.0 customimage:1.0.1
This command adds a patch tag "1.0.1" to "customimage:1.0". It supports semantic versioning for custom-built images, enabling precise updates in release cycles.
docker tag registry.example.com/app:dev registry.example.com/app:staging
This command tags a development image for staging in a private registry. It promotes images through environments, maintaining traceability in CI/CD pipelines.
docker tag hello-world example/hello:demo
This command tags "hello-world" as "example/hello:demo". It creates a demonstration reference for educational or verification purposes, without modifying the minimal test image.
Examples of the Docker Top Command
The docker top command displays the running processes within a specified container, similar to the Unix top utility but focused on container internals. It lists process IDs, users, CPU usage, memory, and commands, aiding in performance monitoring and debugging.
docker top mycontainer
This command lists the top processes in the running "mycontainer", showing PID, user, CPU, memory, and command details. It provides a snapshot of resource utilization, useful for identifying high-consumption processes
docker top dbcontainer aux
This command runs top with the "aux" ps option in "dbcontainer", displaying processes sorted by memory usage. It helps diagnose memory leaks or intensive queries in database containers.
docker top webapp -o pid,cmd
Using the -o flag to select PID and command columns, this command lists processes in "webapp". It customizes output for focused analysis, such as verifying running services.
docker top workercontainer
This command displays top processes in "workercontainer". It monitors background tasks, ensuring efficient operation in queue or batch processing setups.
docker top cachecontainer auxww
This command uses "auxww" to show full command lines in "cachecontainer". It reveals detailed arguments, aiding in configuration verification for caching services.
docker top apiservice -o pid,%cpu,%mem
This command lists PID, CPU percentage, and memory percentage for processes in "apiservice". It focuses on performance metrics, supporting optimization in API endpoints.
docker top debugcontainer
This command shows top processes in "debugcontainer". It assists in real-time debugging, identifying anomalous behavior in experimental setups.
docker top mongocontainer aux
This command displays memory-sorted processes in "mongocontainer". It helps monitor NoSQL database operations, detecting resource spikes.
docker top jenkinscontainer -o pid,user,cmd
This command lists PID, user, and command for "jenkinscontainer". It verifies CI/CD processes, ensuring secure and efficient builds.
docker top --help
This command displays help for docker top, explaining options and ps arguments. It provides guidance for advanced process monitoring.