Skip to content

[WIP] Docker ps custom formatting.#12931

Closed
calavera wants to merge 1 commit intomoby:masterfrom
calavera:ps_format
Closed

[WIP] Docker ps custom formatting.#12931
calavera wants to merge 1 commit intomoby:masterfrom
calavera:ps_format

Conversation

@calavera
Copy link
Contributor

@calavera calavera commented May 1, 2015

This is a generalization of #11943 and #10255 to allow awesome custom formatting!

It follows Docker convention to expose a go template to allow formatting. The default table format for docker ps can be expressed as:

table {{.ID}}\t{{.ImageId}}\t{{.Command}}...

This also allows to display all the labels for a container with {{.Labels}} or a specific label with {{(.Label "com.docker.cpu")}}

TODO:

  • Allow to change the default format by configuration, so swarm can show label columns
  • Test
  • Documentation

Signed-off-by: David Calavera [email protected]

@thaJeztah
Copy link
Member

Hm, I like the awesomeness, but I'm -1 on having the --format option act really different from the other --format flags already used (e.g. docker inspect --format), which use standard Go templates.

I would not mind these options if the flag had a different name (e.g. --template), and (additionally) a --format that accepts a standard Go template. After all, we teach users to use Go-templates for the other options so it would be nice if they could re-use that knowledge here.

Again, I do like the awesomeness and greatly appreciate the work on this!

@duglin
Copy link
Contributor

duglin commented May 2, 2015

I'm just kind of wondering how we went from "why would we need to reorder/add columns, let them just use the API' to this uber-customizable feature? Not saying I'm against it, but if people were hesitant around just choosing which column to show, I would expect them to be even more concerned about a flag that allowed you to do --format="Hello. My name is %N. You killed my father. Prepare to die."

@duglin
Copy link
Contributor

duglin commented May 2, 2015

I'd like to better understand the usecases for this. I understood the original complaints: text too wide; can't awk it easily; want to choose which columns to show. But right now this feels more like extra coolness w/o a clear customer request/requirement/pain-point that we're trying to solve.

But, as I mention in the other thread, no matter which way we go I would want to expand it to other tabular commands, like images and search, for consistency.

@vieux
Copy link
Contributor

vieux commented May 8, 2015

@calavera we would love to see this feature in docker, for swarm

@aluzzardi
Copy link
Member

@duglin There are now container labels.

Image this use case: docker run --label environment=<staging|prod|test>. You can add a column to docker ps to show the environment for every container.

This is very helpful especially when you start having more than just a few containers.

It becomes even more useful if you can specify the formatting through an environment variable, just like your shell prompt.

@aluzzardi
Copy link
Member

@calavera Is "renaming" supported? Couldn't quite figure that out by looking over the code quickly.

Since by design labels are supposed to be FQDN, they can get pretty nasty (e.g. I'd like to display the com.docker.swarm.id label as Swarm ID)

@calavera
Copy link
Contributor Author

@aluzzardi that can be supported. Right now, it takes the label name splitting the FQDN, for example com.docker.swarm.node becomes NODE in the table header. But we can make it slightly smarter. I just added some documentation with examples about this.

Signed-off-by: David Calavera <[email protected]>
@crosbymichael
Copy link
Contributor

lets move the discussion back to #10255 as the original author expressed desire to finish the PR with additional guidance from maintainers.

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.

8 participants