Return container settings in JSON format

docker inspect --format='{{json .Config.Env}}' container_name

…returns a JSON array:

[
  "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/share/npm-global/bin",
  "NODE_VERSION=12.16.3",
  "YARN_VERSION=1.22.4",
  "NVM_DIR=/usr/local/share/nvm"
]

To find out what data can be printed, show all content as JSON. . represents the context:

docker inspect --format='{{json .}}' container_name
docker inspect --format='{{json .HostConfig.Binds}}' container_name
docker inspect --format='{{.NetworkSettings.IPAddress}}' container_name

Template modifiers

join

join concatenates a list of strings to create a single string. It puts a separator between each element in the list.

docker inspect --format '{{join .Args " , "}}' container

table

table specifies which fields you want to see its output.

docker image list --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}\t{{.Size}}"

json

json encodes an element as a json string.

docker inspect --format '{{json .Mounts}}' container

lower

lower transforms a string into its lowercase representation.

docker inspect --format "{{lower .Name}}" container

split

split slices a string into a list of strings separated by a separator.

docker inspect --format '{{split .Image ":"}}'

title

title capitalizes the first character of a string.

docker inspect --format "{{title .Name}}" container

upper

upper transforms a string into its uppercase representation.

docker inspect --format "{{upper .Name}}" container

println

println prints each value on a new line.

docker inspect --format='{{range .NetworkSettings.Networks}}{{println .IPAddress}}{{end}}' container