Skip to content

docker inspect format extracting single label values #2685

Open
@uecasm

Description

@uecasm

Description

I'm not sure if this is just an omission from the docs or if this is an actual bug in the CLI, but:

I want to be able to docker inspect an image to extract the values of specific labels on the image. This is from a script that can't parse JSON directly, but that's what the --format argument is for, right?

But what is the correct syntax for that? One of the following seemed most correct out of the options I could think of:

Steps to reproduce the issue:

docker inspect --format='{{.Config.Labels."org.label-schema.name"}}' $IMAGE_ID

docker inspect --format='{{.Config.Labels["org.label-schema.name"]}}' $IMAGE_ID

docker inspect --format='{{index .Config.Labels "org.label-schema.name"}}' $IMAGE_ID

Describe the results you received:

Template parsing error: template: :1: bad character U+002D '-'

Template parsing error: template: :1: bad character U+005B '['

Template parsing error: template: :1: unclosed action

Describe the results you expected:

build

The value of the label with that name should be printed.

Additional information you deem important (e.g. issue happens only occasionally):

$ docker inspect --format='{{json .Config.Labels}}' $IMAGE_ID
'map[build_id:8 org.label-schema.build-date:2020-08-14T05:42:00Z org.label-schema.description:Build Environment org.label-schema.name:build org.label-schema.schema-version:1.0 org.label-schema.vcs-ref:f1c5a320b23ec7361f6148a95c6683a9cab16d99 org.label-schema.version:4.0]'

(Which might also be a bug, since this is not JSON output...)

Output of docker version:

Client: Docker Engine - Community
 Version:           19.03.12
 API version:       1.40
 Go version:        go1.13.10
 Git commit:        48a66213fe
 Built:             Mon Jun 22 15:43:18 2020
 OS/Arch:           windows/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.12
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.10
  Git commit:       48a66213fe
  Built:            Mon Jun 22 15:49:27 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

Output of docker info:

Client:
 Debug Mode: false

Server:
 Containers: 4
  Running: 1
  Paused: 0
  Stopped: 3
 Images: 52
 Server Version: 19.03.12
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
 init version: fec3683
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 4.19.104-microsoft-standard
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 20
 Total Memory: 24.81GiB
 Name: docker-desktop
 ID: 3U3Y:XEWF:AGDX:7TZ2:XVJG:SUCD:R2XE:WOK7:XGZO:C3DN:A5PG:K4GS
 Docker Root Dir: /var/lib/docker
 Debug Mode: true
  File Descriptors: 77
  Goroutines: 105
  System Time: 2020-08-21T03:21:10.0077369Z
  EventsListeners: 3
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
 Product License: Community Engine

WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled

Additional environment details (AWS, VirtualBox, physical, etc.):

Physical

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions