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