Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix RestartPolicy.noRestart() so it can disable restart on existing c…
…ontainers

noRestart() returned a policy with an empty Name (""), which the Docker Engine
update endpoint ignores: it only applies RestartPolicy when Name != "". As a
result an existing container could not be switched from always/on-failure back
to no-restart via updateContainerCmd.

Return Name "no" instead - a valid "none" policy (RestartPolicy.IsNone() is true
for both "" and "no") that the daemon actually applies. Update
RestartPolicySerializingTest to match; this also matches what modern Docker sends
for `docker run --restart no`.
  • Loading branch information
jcheng422
jcheng422 committed Aug 17, 2026
commit f31ea1c5b5588a0c41cf751ff1ebb5b4ccf27d46
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private RestartPolicy(int maximumRetryCount, String name) {
* Do not restart the container if it dies. (default)
*/
public static RestartPolicy noRestart() {
return new RestartPolicy();
return new RestartPolicy(0, "no");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class RestartPolicySerializingTest {
// --restart no
public void noRestart() throws Exception {
String json = JSONTestHelper.getMapper().writeValueAsString(RestartPolicy.noRestart());
assertEquals("{\"MaximumRetryCount\":0,\"Name\":\"\"}", json);
assertEquals("{\"MaximumRetryCount\":0,\"Name\":\"no\"}", json);
}

@Test
Expand Down