In the previous step, we saw that the default output of docker plugin inspect
is a large JSON object. While this is useful for detailed analysis, it can be difficult to read quickly. Docker provides a --format
flag that allows you to format the output using Go's text/template package. This is very powerful and allows you to extract specific pieces of information or display the output in a custom way.
Let's try to extract just the plugin ID and name using the --format
flag. We will use the {{.ID}}
and {{.Name}}
template fields to access these properties from the JSON output.
docker plugin inspect --format 'ID: {{.ID}}, Name: {{.Name}}' vieux/sshfs:latest
This command will output a string like ID: <plugin_id>, Name: vieux/sshfs:latest
, where <plugin_id>
is the actual ID of the plugin. This is much more concise and easier to read if you only need specific information.
You can also use the --format
flag to create more complex output. For example, let's display the plugin name and its enabled status. The enabled status is a boolean value, and we can access it using {{.Enabled}}
.
docker plugin inspect --format 'Plugin: {{.Name}}, Enabled: {{.Enabled}}' vieux/sshfs:latest
This will output something like Plugin: vieux/sshfs:latest, Enabled: true
or Plugin: vieux/sshfs:latest, Enabled: false
depending on the plugin's state.
The --format
flag is a very flexible tool for customizing the output of Docker commands. You can explore the structure of the JSON output from the default inspect
command to find other fields you might want to include in your formatted output.