Filter and Format Docker Node PS Output

The following Docker command line is used to filter and display information in a more concise and screen-friendly format. It selectively filters only the services and/or containers currently active with a “running” status on specific Docker nodes.

docker node ps --filter "desired-state=running" --format "table {{.ID}}\\t{{.Name}}\\t{{.Image}}\\t{{.Node}}\\t{{.CurrentState}}\\t{{.Error}}" node1 node2 node3

Here is a detailed explanation of what the command does::

  • Using docker node ps, to retrieve information about services running on Docker nodes.
  • By utilizing the --filter "desired-state=running" flag, it ensures that only services with the desired “running” status are displayed.
  • Define how the output will appear with--format "table {{.ID}}\\t{{.Name}}\\t{{.Image}}\\t{{.Node}}\\t{{.CurrentState}}\\t{{.Error}}"
    It will present the information in a tabulated format, featuring distinct fields:
    • {{.ID}}: Represents the unique identifier of each service.
    • {{.Name}}: Displays the name of each service.
    • {{.Image}}: Docker image name utilized by each service.
    • {{.Node}}: Name of the Docker node on which each service is running.
    • {{.CurrentState}}: Indication whether it is currently in the “running” state..
    • {{.Error}}: In the presence of service-related issues, display corresponding error messages.
    • (!) Note the double-escaped tab \\t
  • Concluding with node1 node2 node3, I specify to exclusively acquire information about services running on the designated nodes named node1, node2, and node3.

Below is an illustration of how this output appears.

In summary, this can be used to effectively filter active services on the provided nodes and present them in a tabular format, highlighting critical details such as service ID, name, Docker image, node association, status, and any potential error messages.