-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docker inspect format extracting single label values #2685
Comments
Ok, some progress. The valid syntax appears to depend which shell I'm using. This works in a Posix shell:
This works in a Windows shell:
So, probably the first part of this is just a doc issue. Can this be added to https://docs.docker.com/engine/reference/commandline/inspect/ ? The non-JSON |
Hmm. yes, I suspect the single-quotes could be an issue on PowerShell (at least, I recall another ticket where someone mentioned that). Trying your original example; building an image with the same labels as your example; docker build -t foo:latest -<<'EOF'
FROM busybox
LABEL build_id="8"
LABEL org.label-schema.build-date="2020-08-14T05:42:00Z"
LABEL org.label-schema.description="Build Environment"
LABEL org.label-schema.name="build"
LABEL org.label-schema.schema-version="1.0"
LABEL org.label-schema.vcs-ref="f1c5a320b23ec7361f6148a95c6683a9cab16d99"
LABEL org.label-schema.version="4.0"
EOF Trying docker inspect: docker image inspect --format='{{index .Config.Labels "org.label-schema.name"}}' foo:latest
# build
Hm, right, so I suspect single quotes were used in the examples to (among others) prevent the The source for that page is located in https://github.com/docker/cli/blob/master/docs/reference/commandline/inspect.md. To prevent repeating that information for every command that has a
Good question; I think the |
Hey 😄 . Your point looks simple and good to facilitate this question @thaJeztah , can I make this change to contribute? |
@maximillianfx yes, feel free to work on improvements! The "central" page about formatting is in the documentation repository, so I guess that one should be updated first; https://github.com/docker/docker.github.io/blob/master/config/formatting.md And then we can include a link to that page in the reference documentation for each command that has a |
Ok, I'll be working on this fix during this week. Thanks! |
@thaJeztah can you see if this little change can do the job? If this first approach is okay, I'll could search into the docs by the |
Not 100% sure if this is related, but feels so. I named a network with a hyphen and also can't retrieve with typical syntax.
|
@ronaldpetty docker network create db-net
docker run -d --name foo --network=db-net nginx:alpine
docker container inspect foo -f '{{index .NetworkSettings.Networks "db-net" "IPAddress"}}'
172.19.0.2 |
Thanks @thaJeztah I didn't think that through, appreciate it. |
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:
Describe the results you received:
Describe the results you expected:
The value of the label with that name should be printed.
Additional information you deem important (e.g. issue happens only occasionally):
(Which might also be a bug, since this is not JSON output...)
Output of
docker version
:Output of
docker info
:Additional environment details (AWS, VirtualBox, physical, etc.):
Physical
The text was updated successfully, but these errors were encountered: