@@ -69,6 +69,9 @@ var createContainerCommand = cli.Command{
69
69
if err := getRuntimeClient (context ); err != nil {
70
70
return err
71
71
}
72
+ if err := getImageClient (context ); err != nil {
73
+ return err
74
+ }
72
75
73
76
opts := createOptions {
74
77
podID : context .Args ().Get (0 ),
@@ -78,7 +81,7 @@ var createContainerCommand = cli.Command{
78
81
},
79
82
}
80
83
81
- ctrID , err := CreateContainer (runtimeClient , opts )
84
+ ctrID , err := CreateContainer (imageClient , runtimeClient , opts )
82
85
if err != nil {
83
86
return fmt .Errorf ("Creating container failed: %v" , err )
84
87
}
@@ -374,13 +377,16 @@ var runContainerCommand = cli.Command{
374
377
if err := getRuntimeClient (context ); err != nil {
375
378
return err
376
379
}
380
+ if err := getImageClient (context ); err != nil {
381
+ return err
382
+ }
377
383
378
384
opts := runOptions {
379
385
configPath : context .Args ().Get (0 ),
380
386
podConfig : context .Args ().Get (1 ),
381
387
}
382
388
383
- err := RunContainer (runtimeClient , opts , context .String ("runtime" ))
389
+ err := RunContainer (imageClient , runtimeClient , opts , context .String ("runtime" ))
384
390
if err != nil {
385
391
return fmt .Errorf ("Running container failed: %v" , err )
386
392
}
@@ -390,27 +396,30 @@ var runContainerCommand = cli.Command{
390
396
391
397
// RunContainer starts a container in the provided sandbox
392
398
func RunContainer (
393
- client pb.RuntimeServiceClient , opts runOptions , runtime string ,
399
+ iClient pb.ImageServiceClient ,
400
+ rClient pb.RuntimeServiceClient ,
401
+ opts runOptions ,
402
+ runtime string ,
394
403
) error {
395
404
// Create the pod
396
405
podSandboxConfig , err := loadPodSandboxConfig (opts .podConfig )
397
406
if err != nil {
398
407
return fmt .Errorf ("load podSandboxConfig failed: %v" , err )
399
408
}
400
- podID , err := RunPodSandbox (runtimeClient , podSandboxConfig , runtime )
409
+ podID , err := RunPodSandbox (rClient , podSandboxConfig , runtime )
401
410
if err != nil {
402
411
return fmt .Errorf ("run pod sandbox failed: %v" , err )
403
412
}
404
413
405
414
// Create the container
406
415
containerOptions := createOptions {podID , & opts }
407
- ctrID , err := CreateContainer (runtimeClient , containerOptions )
416
+ ctrID , err := CreateContainer (iClient , rClient , containerOptions )
408
417
if err != nil {
409
418
return fmt .Errorf ("creating container failed: %v" , err )
410
419
}
411
420
412
421
// Start the container
413
- err = StartContainer (runtimeClient , ctrID )
422
+ err = StartContainer (rClient , ctrID )
414
423
if err != nil {
415
424
return fmt .Errorf ("starting the container %q failed: %v" , ctrID , err )
416
425
}
@@ -419,7 +428,12 @@ func RunContainer(
419
428
420
429
// CreateContainer sends a CreateContainerRequest to the server, and parses
421
430
// the returned CreateContainerResponse.
422
- func CreateContainer (client pb.RuntimeServiceClient , opts createOptions ) (string , error ) {
431
+ func CreateContainer (
432
+ iClient pb.ImageServiceClient ,
433
+ rClient pb.RuntimeServiceClient ,
434
+ opts createOptions ,
435
+ ) (string , error ) {
436
+
423
437
config , err := loadContainerConfig (opts .configPath )
424
438
if err != nil {
425
439
return "" , err
@@ -432,13 +446,19 @@ func CreateContainer(client pb.RuntimeServiceClient, opts createOptions) (string
432
446
}
433
447
}
434
448
449
+ // Try to pull the image before container creation
450
+ image := config .GetImage ().GetImage ()
451
+ if _ , err := PullImage (iClient , image , nil ); err != nil {
452
+ return "" , err
453
+ }
454
+
435
455
request := & pb.CreateContainerRequest {
436
456
PodSandboxId : opts .podID ,
437
457
Config : config ,
438
458
SandboxConfig : podConfig ,
439
459
}
440
460
logrus .Debugf ("CreateContainerRequest: %v" , request )
441
- r , err := client .CreateContainer (context .Background (), request )
461
+ r , err := rClient .CreateContainer (context .Background (), request )
442
462
logrus .Debugf ("CreateContainerResponse: %v" , r )
443
463
if err != nil {
444
464
return "" , err
0 commit comments