Skip to content
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

add --format flag to docker version #14194

Merged
merged 1 commit into from Jul 14, 2015
Merged

add --format flag to docker version #14194

merged 1 commit into from Jul 14, 2015

Conversation

phemmer
Copy link
Contributor

@phemmer phemmer commented Jun 26, 2015

This adds the --format flag to docker version.

Closes #14186

Default output:

$ docker version
Client:
 Version:      1.8.0
 API version:  1.20
 Go version:   go1.4.2
 Git commit:   f5bae0a
 Built:        Tue Jun 23 17:56:00 UTC 2015
 OS/Arch:      linux/amd64

Server:
 Version:      1.8.0
 API version:  1.20
 Go version:   go1.4.2
 Git commit:   f5bae0a
 Built:        Tue Jun 23 17:56:00 UTC 2015
 OS/Arch:      linux/amd64

Get server version:

$ docker version --format '{{.Server.Version}}'
1.8.0

Dump raw data:

$ docker version --format '{{json .}}'
{"Client":{"Version":"1.8.0","ApiVersion":"1.20","GitCommit":"f5bae0a","GoVersion":"go1.4.2","Os":"linux","Arch":"amd64","BuildTime":"Tue Jun 23 17:56:00 UTC 2015"},"ServerOK":true,"Server":{"Version":"1.8.0","ApiVersion":"1.20","GitCommit":"f5bae0a","GoVersion":"go1.4.2","Os":"linux","Arch":"amd64","KernelVersion":"3.13.2-gentoo","BuildTime":"Tue Jun 23 17:56:00 UTC 2015"}}

Dead server:

$ docker version
Client:
 Version:      1.8.0-dev
 API version:  1.20
 Go version:   go1.4.1
 Git commit:   2a8293f-dirty
 Built:        Fri Jun 26 01:38:16 UTC 2015
 OS/Arch:      linux/amd64
Get http:///var/run/docker.sock/v1.20/version: dial unix /var/run/docker.sock: no such file or directory. Are you trying to connect to a TLS-enabled daemon without TLS?

(error goes to STDERR, allowing capturing STDOUT to still work if only client data is needed)

@LK4D4
Copy link
Contributor

LK4D4 commented Jun 26, 2015

Is there any drawbacks for using API for such tasks?

@tianon
Copy link
Member

tianon commented Jun 26, 2015

I'm a big +1, but I agree with @LK4D4 that it seems like this would be better as a client-side feature -- that way we could even use this to just get the version of the client binary when the server isn't responding or isn't up, which right now looks like this (and is useful):

$ DOCKER_HOST=unix:///not/a/file.sock docker version
Client:
 Version:      1.8.0-dev
 API version:  1.20
 Go version:   go1.4.2
 Git commit:   b96f109-dirty
 Built:        Fri Jun 26 16:26:11 UTC 2015
 OS/Arch:      linux/amd64
Get http:///not/a/file.sock/v1.20/version: dial unix /not/a/file.sock: no such file or directory. Are you trying to connect to a TLS-enabled daemon without TLS?

@tianon
Copy link
Member

tianon commented Jun 26, 2015

ie, something like this would happen: (with that warning going to stderr)

$ docker version -f '{{.Client.Version}}'
Get http:///not/a/file.sock/v1.20/version: dial unix /not/a/file.sock: no such file or directory. Are you trying to connect to a TLS-enabled daemon without TLS?
1.8.0-dev

@duglin
Copy link
Contributor

duglin commented Jun 26, 2015

:-) with that format string I kind of wonder why we're even hitting the daemon

@phemmer
Copy link
Contributor Author

phemmer commented Jun 26, 2015

it seems like this would be better as a client-side feature

I'm not quite following. This is a client side feature.

ie, something like this would happen: (with that warning going to stderr)

$ docker version -f '{{.Client.Version}}'
Get http:///not/a/file.sock/v1.20/version: dial unix /not/a/file.sock: no such file or directory. Are you trying to connect to a TLS-enabled daemon without TLS?
1.8.0-dev

That is what happens (except the order of the lines is reversed).

with that format string I kind of wonder why we're even hitting the daemon

Yeah, that is one down side. But the only way I can see to make that happen is to add a function to the template map which fetches the server data. And I think that makes the templating dirty.
And the current behavior is also no change from previous. If you wanted to do docker version | grep "Client version", it still hit the server.

@icecrime
Copy link
Contributor

LGTM

@jessfraz
Copy link
Contributor

LGTM, so sorry needs rebase, we are almost through the tunnel to the end :)

Signed-off-by: Patrick Hemmer <patrick.hemmer@gmail.com>
@phemmer
Copy link
Contributor Author

phemmer commented Jul 14, 2015

Rebased.

@jessfraz
Copy link
Contributor

LGTM

jessfraz pushed a commit that referenced this pull request Jul 14, 2015
add --format flag to `docker version`
@jessfraz jessfraz merged commit e221291 into moby:master Jul 14, 2015
@jessfraz
Copy link
Contributor

thanks!

cmd := cli.Subcmd("version", nil, "Show the Docker version information.", true)
tmplStr := cmd.String([]string{"f", "#format", "-format"}, "", "Format the output using the given go template")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phemmer i just noticed: you shouldn't use #format, that's for old flags, you are introducing a new one here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @phemmer could you take care of this, or want someone else to do so?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants