chore(docker): share failed container cleanup policy (#6392)

Use one private helper from create and createAndStart while preserving ordinary cleanup, ephemeral volume removal and suppressed cleanup failures.

Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
Andre Kurait authored and GitHub committed 2026-10-23 22:39:47 -04:00
1 parent ec7cc6713f
commit f10d98a9f1
1 file changed
+7 -11
@@ -142,16 +142,16 @@ public class ContainerLifecycleManager {
try {
return withPublishedHostPorts(startCreated(containerId, spec), spec);
} catch (RuntimeException failure) {
if (removeAnonymousVolumes) {
removeFailedEphemeralContainer(containerId, failure);
} else {
removeIfExists(containerId);
}
removeFailedContainer(containerId, failure, removeAnonymousVolumes);
throw failure;
}
}
private void removeFailedEphemeralContainer(String containerId, RuntimeException failure) {
private void removeFailedContainer(String containerId, RuntimeException failure, boolean removeAnonymousVolumes) {
if (!removeAnonymousVolumes) {
removeIfExists(containerId);
return;
}
try {
removeIfExistsStrict(containerId, true);
} catch (RuntimeException cleanupFailure) {
@@ -203,11 +203,7 @@ public class ContainerLifecycleManager {
try {
attachNetworkBeforeStart(containerId, spec);
} catch (RuntimeException e) {
if (removeAnonymousVolumes) {
removeFailedEphemeralContainer(containerId, e);
} else {
removeIfExists(containerId);
}
removeFailedContainer(containerId, e, removeAnonymousVolumes);
throw new IllegalStateException(
"Failed to attach pre-start network configuration for container " + containerId, e);
}