@@ -958,6 +958,12 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
958
958
for i := range containers {
959
959
ctr := containers [i ]
960
960
961
+ removeContainer := func () {
962
+ if _ , _ , err := ic .removeContainer (ctx , ctr .Container , entities.RmOptions {}); err != nil {
963
+ logrus .Errorf ("Removing container %s: %v" , ctr .ID (), err )
964
+ }
965
+ }
966
+
961
967
if options .Attach {
962
968
err = terminal .StartAttachCtr (ctx , ctr .Container , options .Stdout , options .Stderr , options .Stdin , options .DetachKeys , options .SigProxy , true )
963
969
if errors .Is (err , define .ErrDetach ) {
@@ -991,9 +997,7 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
991
997
ExitCode : exitCode ,
992
998
})
993
999
if ctr .AutoRemove () {
994
- if _ , _ , err := ic .removeContainer (ctx , ctr .Container , entities.RmOptions {}); err != nil {
995
- logrus .Errorf ("Removing container %s: %v" , ctr .ID (), err )
996
- }
1000
+ removeContainer ()
997
1001
}
998
1002
return reports , fmt .Errorf ("unable to start container %s: %w" , ctr .ID (), err )
999
1003
}
@@ -1002,6 +1006,9 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
1002
1006
if err2 != nil {
1003
1007
logrus .Errorf ("Waiting for container %s: %v" , ctr .ID (), err2 )
1004
1008
}
1009
+ if ctr .AutoRemove () && ! ctr .ShouldRestart (ctx ) {
1010
+ removeContainer ()
1011
+ }
1005
1012
reports = append (reports , & entities.ContainerStartReport {
1006
1013
Id : ctr .ID (),
1007
1014
RawInput : ctr .rawInput ,
@@ -1038,9 +1045,7 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
1038
1045
}
1039
1046
report .Err = fmt .Errorf ("unable to start container %q: %w" , ctr .ID (), err )
1040
1047
if ctr .AutoRemove () {
1041
- if _ , _ , err := ic .removeContainer (ctx , ctr .Container , entities.RmOptions {}); err != nil {
1042
- logrus .Errorf ("Removing container %s: %v" , ctr .ID (), err )
1043
- }
1048
+ removeContainer ()
1044
1049
}
1045
1050
reports = append (reports , report )
1046
1051
continue
0 commit comments