diff --git a/cli/command/image/history.go b/cli/command/image/history.go
index 73a893fa976c..85754dfb4374 100644
--- a/cli/command/image/history.go
+++ b/cli/command/image/history.go
@@ -2,7 +2,8 @@ package image
import (
"context"
-
+ "fmt"
+ "github.com/containerd/platforms"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
@@ -13,7 +14,8 @@ import (
)
type historyOptions struct {
- image string
+ image string
+ platform string
human bool
quiet bool
@@ -45,12 +47,28 @@ func NewHistoryCommand(dockerCli command.Cli) *cobra.Command {
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only show image IDs")
flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Don't truncate output")
flags.StringVar(&opts.format, "format", "", flagsHelper.FormatHelp)
+ flags.StringVar(&opts.platform, "platform", "",
+ `Specify a platform from a multi-platform image to show the history for.
+If the platform is not specified, the host platform is preferred if it's available, otherwise any available platform is used.
+
+Format: os[/arch[/variant]]
+Example: "linux/amd64"`)
return cmd
}
func runHistory(ctx context.Context, dockerCli command.Cli, opts historyOptions) error {
- history, err := dockerCli.Client().ImageHistory(ctx, opts.image, image.HistoryOptions{})
+ var options image.HistoryOptions
+ if opts.platform != "" {
+ p, err := platforms.Parse(opts.platform)
+ if err != nil {
+ _, _ = fmt.Fprintf(dockerCli.Err(), "Invalid platform %s", opts.platform)
+ return err
+ }
+ options.Platform = &p
+ }
+
+ history, err := dockerCli.Client().ImageHistory(ctx, opts.image, options)
if err != nil {
return err
}
diff --git a/docs/reference/commandline/history.md b/docs/reference/commandline/history.md
index 7705c70bcac8..ab7079615104 100644
--- a/docs/reference/commandline/history.md
+++ b/docs/reference/commandline/history.md
@@ -14,6 +14,7 @@ Show the history of an image
| `--format` | `string` | | Format output using a custom template:
'table': Print output in table format with column headers (default)
'table TEMPLATE': Print output in table format using the given Go template
'json': Print in JSON format
'TEMPLATE': Print output using the given Go template.
Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates |
| `-H`, `--human` | `bool` | `true` | Print sizes and dates in human readable format |
| `--no-trunc` | `bool` | | Don't truncate output |
+| `--platform` | `string` | | Specify a platform from a multi-platform image to show the history for.
If the platform is not specified, the host platform is preferred if it's available, otherwise any available platform is used.
Format: os[/arch[/variant]]
Example: `linux/amd64` |
| `-q`, `--quiet` | `bool` | | Only show image IDs |
diff --git a/docs/reference/commandline/image_history.md b/docs/reference/commandline/image_history.md
index 7ed258a9f5be..117d51615da2 100644
--- a/docs/reference/commandline/image_history.md
+++ b/docs/reference/commandline/image_history.md
@@ -14,6 +14,7 @@ Show the history of an image
| [`--format`](#format) | `string` | | Format output using a custom template:
'table': Print output in table format with column headers (default)
'table TEMPLATE': Print output in table format using the given Go template
'json': Print in JSON format
'TEMPLATE': Print output using the given Go template.
Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates |
| `-H`, `--human` | `bool` | `true` | Print sizes and dates in human readable format |
| `--no-trunc` | `bool` | | Don't truncate output |
+| `--platform` | `string` | | Specify a platform from a multi-platform image to show the history for.
If the platform is not specified, the host platform is preferred if it's available, otherwise any available platform is used.
Format: os[/arch[/variant]]
Example: `linux/amd64` |
| `-q`, `--quiet` | `bool` | | Only show image IDs |