@@ -125,14 +125,12 @@ var listImageCommand = cli.Command{
125
125
printHeader = false
126
126
fmt .Fprintln (w , "IMAGE\t TAG\t IMAGE ID\t SIZE" )
127
127
}
128
- repoTags := "<none>"
129
- if image .RepoTags != nil {
130
- repoTags = image .RepoTags [0 ]
131
- }
132
- repoTagsPair := strings .Split (repoTags , ":" )
128
+ repoTagPairs := normalizeRepoTagPair (image .RepoTags , image .RepoDigests )
133
129
size := units .HumanSizeWithPrecision (float64 (image .GetSize_ ()), 3 )
134
130
trunctedImage := strings .TrimPrefix (image .Id , "sha256:" )[:truncatedImageIDLen ]
135
- fmt .Fprintf (w , "%s\t %s\t %s\t %s\n " , repoTagsPair [0 ], repoTagsPair [1 ], trunctedImage , size )
131
+ for _ , repoTagPair := range repoTagPairs {
132
+ fmt .Fprintf (w , "%s\t %s\t %s\t %s\n " , repoTagPair [0 ], repoTagPair [1 ], trunctedImage , size )
133
+ }
136
134
continue
137
135
}
138
136
fmt .Printf ("ID: %s\n " , image .Id )
@@ -270,6 +268,29 @@ func getAuth(creds string) (*pb.AuthConfig, error) {
270
268
}, nil
271
269
}
272
270
271
+ // Ideally repo tag should always be image:tag.
272
+ // The repoTags is nil when pulling image by repoDigest,Then we will show image name instead.
273
+ func normalizeRepoTagPair (repoTags []string , repoDigests []string ) (repoTagPairs [][]string ) {
274
+ if len (repoTags ) == 0 {
275
+ if len (repoDigests ) == 0 {
276
+ repoTagPairs = append (repoTagPairs ,[]string {"errorRepoDigest" , "errorRepoDigest" })
277
+ return
278
+ }
279
+ imageName := strings .Split (repoDigests [0 ], "@" )[0 ]
280
+ repoTagPairs = append (repoTagPairs ,[]string {imageName , "<none>" })
281
+ return
282
+ }
283
+
284
+ for _ , repoTag := range repoTags {
285
+ if idx := strings .Index (repoTag , ":" ); idx == - 1 {
286
+ repoTagPairs = append (repoTagPairs ,[]string {"errorRepoTag" , "errorRepoTag" })
287
+ continue
288
+ }
289
+ repoTagPairs = append (repoTagPairs , strings .Split (repoTag , ":" ))
290
+ }
291
+ return
292
+ }
293
+
273
294
// PullImage sends a PullImageRequest to the server, and parses
274
295
// the returned PullImageResponse.
275
296
func PullImage (client pb.ImageServiceClient , image string , auth * pb.AuthConfig ) (* pb.PullImageResponse , error ) {
0 commit comments