@@ -234,7 +234,7 @@ func Create(ctx context.Context, client *containerd.Client, args []string, netMa
234
234
}
235
235
cOpts = append (cOpts , rtCOpts ... )
236
236
237
- lCOpts , err := withContainerLabels (options .Label , options .LabelFile )
237
+ lCOpts , err := withContainerLabels (options .Label , options .LabelFile , ensuredImage )
238
238
if err != nil {
239
239
return nil , nil , err
240
240
}
@@ -504,7 +504,15 @@ func withNerdctlOCIHook(cmd string, args []string) (oci.SpecOpts, error) {
504
504
}, nil
505
505
}
506
506
507
- func withContainerLabels (label , labelFile []string ) ([]containerd.NewContainerOpts , error ) {
507
+ func withContainerLabels (label , labelFile []string , ensuredImage * imgutil.EnsuredImage ) ([]containerd.NewContainerOpts , error ) {
508
+ var opts []containerd.NewContainerOpts
509
+
510
+ // add labels defined by image
511
+ if ensuredImage != nil {
512
+ imageLabelOpts := containerd .WithAdditionalContainerLabels (ensuredImage .ImageConfig .Labels )
513
+ opts = append (opts , imageLabelOpts )
514
+ }
515
+
508
516
labelMap , err := readKVStringsMapfFromLabel (label , labelFile )
509
517
if err != nil {
510
518
return nil , err
@@ -517,7 +525,9 @@ func withContainerLabels(label, labelFile []string) ([]containerd.NewContainerOp
517
525
}
518
526
}
519
527
o := containerd .WithAdditionalContainerLabels (labelMap )
520
- return []containerd.NewContainerOpts {o }, nil
528
+ opts = append (opts , o )
529
+
530
+ return opts , nil
521
531
}
522
532
523
533
func readKVStringsMapfFromLabel (label , labelFile []string ) (map [string ]string , error ) {
0 commit comments