@@ -539,10 +539,26 @@ func (cl *Client) ContainerReplace(containerID string, image string, tag string)
539
539
return err
540
540
}
541
541
542
+ // stopping old container
543
+ killAfter := time .Second * 5
544
+ stopErr := cl .ContainerStop (containerID , & killAfter )
545
+ if stopErr != nil {
546
+ if cl .log != nil {
547
+ cl .log .Error ("failed to stop old container" , containerID , stopErr )
548
+ }
549
+ return stopErr
550
+ }
551
+
542
552
originalContainerName := originalContainer .Name
543
553
tempContainerName := originalContainerName + "_temp"
544
554
rErr := cl .ContainerRename (originalContainer .ID , tempContainerName )
545
555
if rErr != nil {
556
+ sErr := cl .ContainerStart (originalContainer .ID )
557
+ if sErr != nil {
558
+ if cl .log != nil {
559
+ cl .log .Error ("failed to start an old container back up after failing to rename" , sErr )
560
+ }
561
+ }
546
562
return rErr
547
563
}
548
564
@@ -554,6 +570,7 @@ func (cl *Client) ContainerReplace(containerID string, image string, tag string)
554
570
if ccErr != nil {
555
571
// revert renaming back the old container
556
572
rbErr := cl .ContainerRename (containerID , originalContainerName )
573
+ rbErr = cl .ContainerStart (containerID )
557
574
if rbErr != nil {
558
575
return rbErr
559
576
}
@@ -570,6 +587,7 @@ func (cl *Client) ContainerReplace(containerID string, image string, tag string)
570
587
}
571
588
// undo previous changes to origial container and remove newly created container
572
589
cerr := cl .ContainerRename (containerID , originalContainerName )
590
+ cerr = cl .ContainerStart (containerID )
573
591
cerr = cl .ContainerRemove (newlyCreatedContainer .ID )
574
592
if cerr != nil {
575
593
return cerr
@@ -578,16 +596,6 @@ func (cl *Client) ContainerReplace(containerID string, image string, tag string)
578
596
return sErr
579
597
}
580
598
581
- // removing old container
582
- killAfter := time .Second * 5
583
- stopErr := cl .ContainerStop (containerID , & killAfter )
584
- if stopErr != nil {
585
- if cl .log != nil {
586
- cl .log .Error ("failed to stop old container" , containerID , stopErr )
587
- }
588
- return stopErr
589
- }
590
-
591
599
_ , remErr := cl .ContainersPrune (filters .NewArgs ())
592
600
if remErr != nil {
593
601
if cl .log != nil {
0 commit comments