Docker Config Reference (docker node)

We go over using the docker node command!

Docker Config Reference (docker node)
docker node usage examples

In the context of Docker orchestration, a Docker node refers to a physical or virtual machine that participates in a Docker Swarm cluster, equipped with the Docker Engine to enable distributed container management. Nodes are categorized into two primary types: manager nodes, which coordinate cluster activities such as task scheduling, service discovery, and maintaining the desired state; and worker nodes, which execute the assigned container tasks. This structure facilitates scalability, high availability, and fault tolerance in multi-host environments. Management of nodes is achieved through the docker node command-line interface, which supports operations such as listing, inspecting, promoting, demoting, and updating node properties.

docker node ls

This command lists all nodes in the Docker Swarm cluster, displaying details such as node ID, hostname, status, availability, and role (manager or worker). It provides a comprehensive overview of the cluster's composition, which is essential for monitoring and managing distributed container orchestration.

docker node ls --quiet

Utilizing the --quiet flag, this command outputs only the node IDs of the Swarm cluster nodes, suppressing additional details. This format is particularly suitable for scripting or automation tasks where concise identifiers are required without extraneous information.

docker node ls --format "{{.ID}} {{.Hostname}}"

This command lists Swarm nodes using a custom Go template format to display only the node ID and hostname. It enables selective extraction of attributes, facilitating integration with other tools or customized reporting.

docker node inspect self

This command inspects the current node (referred to as "self") in the Swarm cluster, returning detailed JSON-formatted information including configuration, status, and specifications. It is useful for self-diagnostic purposes on the executing host.

docker node inspect node1

This command inspects a specific node named "node1" in the Swarm cluster, providing comprehensive details in JSON format about its state, role, and resources. It supports targeted analysis for troubleshooting individual nodes.

docker node inspect --pretty node1

With the --pretty flag, this command inspects "node1" and formats the output in a human-readable structure rather than raw JSON, enhancing readability for administrative reviews without requiring external parsing tools.

docker node promote node2

This command promotes the worker node "node2" to a manager role in the Swarm cluster, increasing the number of managers for improved fault tolerance and leadership distribution.

docker node demote node1

This command demotes the manager node "node1" to a worker role, reducing the manager count while maintaining the node's participation in task execution, which is beneficial for optimizing cluster leadership.

docker node update --availability drain node3

This command updates "node3" to set its availability to "drain", preventing new tasks from being scheduled on it and allowing existing tasks to complete or migrate, ideal for maintenance or decommissioning.

docker node update --label-add env=prod node4

This command updates "node4" by adding a label "env=prod", enabling node-specific metadata for scheduling constraints or organizational purposes in service deployments.

docker node update --label-rm env node4

This command updates "node4" by removing the label "env", clearing previously set metadata to adjust scheduling behaviors or simplify node configurations.

docker node ps

This command lists tasks running on all nodes in the Swarm cluster, showing details like task ID, name, image, and status. It provides a cluster-wide view of workload distribution.

docker node ps self

This command lists tasks running on the current node ("self"), offering insights into local workload for performance monitoring or issue resolution on the executing host.

docker node ps node5

This command lists tasks specifically on "node5", allowing focused examination of a single node's assignments and states for targeted management.

docker node ps --filter desired-state=running

This command lists tasks filtered by the desired state of "running", narrowing results to active tasks across the cluster for operational oversight.

docker node rm node6

This command removes "node6" from the Swarm cluster, provided it is not a manager or has no running tasks, facilitating cluster resizing or node replacement.

docker node rm --force node7

With the --force flag, this command forcibly removes "node7" from the cluster, even if it has running tasks or is a manager, overriding safety checks for urgent scenarios.

docker node update --availability active node3

This command updates "node3" to set its availability to "active", allowing it to accept new tasks after a period of maintenance or draining.

docker node update --availability pause node8

This command updates "node8" to "pause" availability, temporarily halting new task scheduling while keeping existing tasks running, suitable for short-term interventions.

docker node update --role manager node9

This command updates "node9" to assign it the manager role, equivalent to promotion, for expanding leadership capabilities in the cluster.

docker node update --role worker node10

This command updates "node10" to assign it the worker role, equivalent to demotion, for reallocating resources toward task execution rather than management.

docker node ls --filter role=manager

This command lists nodes filtered by the manager role, isolating leadership nodes for focused monitoring or configuration.

docker node ls --filter role=worker

This command lists nodes filtered by the worker role, highlighting execution nodes for workload distribution analysis.

docker node inspect --format '{{json .Spec}}' node1

This command inspects "node1" and formats the output to display only the specification section in JSON, useful for extracting configuration details programmatically.

docker node ps --format "table {{.ID}}\t{{.Name}}\t{{.Status}}"

This command lists tasks in a tabular format with selected columns (ID, Name, Status), improving readability for human operators.

docker node update --label-add key=value node11

This command updates "node11" by adding a label "key=value", supporting custom metadata for advanced scheduling or filtering.

docker node ls --format "table {{.ID}}\t{{.Hostname}}\t{{.Status}}\t{{.Availability}}"

This command lists nodes in a table with ID, Hostname, Status, and Availability, providing a structured summary for cluster health checks.

docker node inspect node12 --format '{{.Status.Addr}}'

This command inspects "node12" and extracts only the IP address using a format template, aiding in network configuration or scripting.

docker node ps --quiet

With the --quiet flag, this command lists only task IDs across the cluster, offering minimal output for automation.

docker node --help

This command displays help documentation for the docker node command, including subcommands and options, serving as a reference for users to explore functionality.