summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2020-02-17 08:58:31 +0100
committerValentin Rothberg <rothberg@redhat.com>2020-02-17 15:22:21 +0100
commit3c2cc6786742ae873d7055ea3921ea5243d92898 (patch)
tree0ae6c8f792343f5e7716b1aeb9375cf2f73a2e6b
parent92dbcb8841abae35658e5da1bf6eddee7669ea75 (diff)
downloadpodman-3c2cc6786742ae873d7055ea3921ea5243d92898.tar.gz
podman-3c2cc6786742ae873d7055ea3921ea5243d92898.tar.bz2
podman-3c2cc6786742ae873d7055ea3921ea5243d92898.zip
podman-ps: support image IDs
Support printing image IDs via `--format "{{.ImageID}}"`. Fixes: #5160 Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
-rw-r--r--cmd/podman/shared/container.go8
-rw-r--r--docs/source/markdown/podman-ps.1.md3
-rw-r--r--test/e2e/ps_test.go3
3 files changed, 11 insertions, 3 deletions
diff --git a/cmd/podman/shared/container.go b/cmd/podman/shared/container.go
index ff3846e70..b5a1e7104 100644
--- a/cmd/podman/shared/container.go
+++ b/cmd/podman/shared/container.go
@@ -30,6 +30,7 @@ import (
const (
cidTruncLength = 12
podTruncLength = 12
+ iidTruncLength = 12
cmdTruncLength = 17
)
@@ -66,6 +67,7 @@ type BatchContainerStruct struct {
type PsContainerOutput struct {
ID string
Image string
+ ImageID string
Command string
Created string
Ports string
@@ -203,7 +205,7 @@ func NewBatchContainer(r *libpod.Runtime, ctr *libpod.Container, opts PsOptions)
status = "Error"
}
- _, imageName := ctr.Image()
+ imageID, imageName := ctr.Image()
cid := ctr.ID()
podID := ctr.PodID()
if !opts.NoTrunc {
@@ -214,6 +216,9 @@ func NewBatchContainer(r *libpod.Runtime, ctr *libpod.Container, opts PsOptions)
if len(command) > cmdTruncLength {
command = command[0:cmdTruncLength] + "..."
}
+ if len(imageID) > iidTruncLength {
+ imageID = imageID[0:iidTruncLength]
+ }
}
ports, err := ctr.PortMappings()
@@ -223,6 +228,7 @@ func NewBatchContainer(r *libpod.Runtime, ctr *libpod.Container, opts PsOptions)
pso.ID = cid
pso.Image = imageName
+ pso.ImageID = imageID
pso.Command = command
pso.Created = created
pso.Ports = portsToString(ports)
diff --git a/docs/source/markdown/podman-ps.1.md b/docs/source/markdown/podman-ps.1.md
index 23bf9f45d..2f8112aab 100644
--- a/docs/source/markdown/podman-ps.1.md
+++ b/docs/source/markdown/podman-ps.1.md
@@ -55,7 +55,8 @@ Valid placeholders for the Go template are listed below:
| **Placeholder** | **Description** |
| --------------- | ------------------------------------------------ |
| .ID | Container ID |
-| .Image | Image ID/Name |
+| .Image | Image Name/ID |
+| .ImageID | Image ID |
| .Command | Quoted command used |
| .CreatedAt | Creation time for container |
| .RunningFor | Time elapsed since container was started |
diff --git a/test/e2e/ps_test.go b/test/e2e/ps_test.go
index 48dd186e2..adbb9c16c 100644
--- a/test/e2e/ps_test.go
+++ b/test/e2e/ps_test.go
@@ -170,10 +170,11 @@ var _ = Describe("Podman ps", func() {
_, ec, _ := podmanTest.RunLsContainer("test1")
Expect(ec).To(Equal(0))
- result := podmanTest.Podman([]string{"ps", "-a", "--format", "table {{.ID}} {{.Image}} {{.Labels}}"})
+ result := podmanTest.Podman([]string{"ps", "-a", "--format", "table {{.ID}} {{.Image}} {{.ImageID}} {{.Labels}}"})
result.WaitWithDefaultTimeout()
Expect(strings.Contains(result.OutputToStringArray()[0], "table")).To(BeFalse())
Expect(strings.Contains(result.OutputToStringArray()[0], "ID")).To(BeTrue())
+ Expect(strings.Contains(result.OutputToStringArray()[0], "ImageID")).To(BeTrue())
Expect(strings.Contains(result.OutputToStringArray()[1], "alpine:latest")).To(BeTrue())
Expect(result.ExitCode()).To(Equal(0))
})