docker / docker/compose

[FEATURE REQUEST] Add GO templating capabilities to images and/or list commands

Open
#12,948 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

kind/feature
Dominant language
Go
Stars
38.2k
Forks
5.8k
Avg merge
2d 14h
Merged PRs (30d)
55

Description

Description

There are situations where I'd like to down all projects and this requires access to all project names in a machine readable format.
Given that several docker CLI/compose commands provide templating capabilities with the --format flag I'd expect to solve this with:

docker compose ls --format '{{.Name}}' | xargs -I{} docker compose -p {} down 

But docker compose ls --format <format> only offers json or table format therefore it's only possible to get project names using external applications.

If using table format you'd have to hack a shell pipeline.

docker compose ls | tail -n +2 | awk '{print $1}' | xargs -I{} docker compose -p {} down 

If using json format, even though json is machine readable, it requires you to pipe to a parser, such as jq, which very likely it's not available.

docker compose ls --format json | jq '.[].Name' | xargs -I{} docker compose -p {} down

The docker CLI and compose already provide GO Templates formatting for several commands such as:

  • docker ps --format <TEMPLATE>
  • docker images --format <TEMPLATE>
  • docker stats --format <TEMPLATE>
  • docker compose ps --format <TEMPLATE>

The list goes on.

In compose there is compose images and compose ls which not only are not able to handle Templates but they also print JSON in a different way than the ones that support Templates.
The commands that have support print each object as a separate JSON in a different line, while the ones that don't print a JSON list in a single line:

docker images --format json
# {"Containers":"N/A","CreatedAt":"2014-07-19 04:02:32 -0300 -03","CreatedSince":"10 years ago","Digest":"\u003cnone\u003e","ID":"350b164e7ae1","Repository":"gcr.io/google-containers/pause","SharedSize":"N/A","Size":"240kB","Tag":"latest","UniqueSize":"N/A","VirtualSize":"239.8kB"}
# {"Containers":"N/A","CreatedAt":"1979-12-31 21:00:00 -0300 -03","CreatedSince":"45 years ago","Digest":"\u003cnone\u003e","ID":"f576b2d0af25","Repository":"test","SharedSize":"N/A","Size":"2.06GB","Tag":"latest","UniqueSize":"N/A","VirtualSize":"2.056GB"}


docker compose images --format json
# [{"ID":"sha256:350b164e7ae1dcddeffadd65c76226c9b6dc5553f5179153fb0e36b78f2a5e06","ContainerName":"test_1-compose_test-1","Repository":"gcr.io/google-containers/pause","Tag":"latest","Size":239840,"LastTagTime":"0001-01-01T00:00:00Z"},{"ID":"sha256:350b164e7ae1dcddeffadd65c76226c9b6dc5553f5179153fb0e36b78f2a5e06","ContainerName":"test_1-compose_test_2-1","Repository":"gcr.io/google-containers/pause","Tag":"latest","Size":239840,"LastTagTime":"0001-01-01T00:00:00Z"}]

Implementing templating capabilities for these commands would change the output format but only to conform with already existing behavior.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the docker compose ls and docker compose images entry points and compare their current --format json behavior with commands such as docker ps and docker images. Done means both commands accept Go templates and produce output consistent with existing template-capable commands, while preserving the requested machine-readable behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker-compose, go
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.