From fa14607f9040685bd143aa2e50128b93c2ebea45 Mon Sep 17 00:00:00 2001 From: Dean Chen <862469039@qq.com> Date: Wed, 5 Aug 2026 23:52:56 +0500 Subject: [PATCH] docs: show how to read map keys with special characters in inspect Go field syntax only works for identifier-like keys. Labels and network names often contain dots or hyphens, so document index-based access and a Windows quoting example. Fixes #2685 Signed-off-by: Dean Chen <862469039@qq.com> --- docs/reference/commandline/inspect.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/reference/commandline/inspect.md b/docs/reference/commandline/inspect.md index 53cf6fbec965..051c7aa7cd4b 100644 --- a/docs/reference/commandline/inspect.md +++ b/docs/reference/commandline/inspect.md @@ -123,6 +123,30 @@ of that. Then, specify the `HostPort` field to get the public address. $ docker inspect --format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID ``` +### Get a single label value + +Image and container labels live in a string map (for example `.Config.Labels`). +Field syntax only works for keys that are valid Go identifiers, so keys with +dots, hyphens, or other special characters need the template `index` function: + +```console +$ docker inspect --format='{{index .Config.Labels "org.label-schema.name"}}' $IMAGE_ID +``` + +On Windows shells, use double quotes around the template and escape the inner +quotes: + +```console +$ docker inspect --format="{{index .Config.Labels \"org.label-schema.name\"}}" %IMAGE_ID% +``` + +The same pattern applies to other maps with non-identifier keys, such as +network names: + +```console +$ docker inspect --format='{{index .NetworkSettings.Networks "db-net" "IPAddress"}}' $INSTANCE_ID +``` + ### Get a subsection in JSON format If you request a field which is itself a structure containing other fields, by