diff --git a/docs/man/docker-create.1.md b/docs/man/docker-create.1.md index e5c4fa600f..d5166ca93a 100644 --- a/docs/man/docker-create.1.md +++ b/docs/man/docker-create.1.md @@ -157,7 +157,7 @@ This value should always larger than **-m**, so you should alway use this with * **--read-only**=*true*|*false* Mount the container's root filesystem as read only. -**--restart**="" +**--restart**="no" Restart policy to apply when a container exits (no, on-failure[:max-retry], always) **--security-opt**=[] diff --git a/docs/man/docker-run.1.md b/docs/man/docker-run.1.md index cbb835b87b..587b9a2cd5 100644 --- a/docs/man/docker-run.1.md +++ b/docs/man/docker-run.1.md @@ -294,7 +294,7 @@ outside of a container on the host. to write files anywhere. By specifying the `--read-only` flag the container will have its root filesystem mounted as read only prohibiting any writes. -**--restart**="" +**--restart**="no" Restart policy to apply when a container exits (no, on-failure[:max-retry], always) **--rm**=*true*|*false* diff --git a/docs/sources/reference/commandline/cli.md b/docs/sources/reference/commandline/cli.md index f8073d8505..efcf5bff81 100644 --- a/docs/sources/reference/commandline/cli.md +++ b/docs/sources/reference/commandline/cli.md @@ -802,7 +802,7 @@ Creates a new container. -p, --publish=[] Publish a container's port(s) to the host --privileged=false Give extended privileges to this container --read-only=false Mount the container's root filesystem as read only - --restart="" Restart policy to apply when a container exits + --restart="no" Restart policy to apply when a container exits --security-opt=[] Security Options -t, --tty=false Allocate a pseudo-TTY -u, --user="" Username or UID diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index f348e54315..52e8b12164 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -3183,6 +3183,25 @@ func TestRunOOMExitCode(t *testing.T) { logDone("run - exit code on oom") } +func TestRunSetDefaultRestartPolicy(t *testing.T) { + defer deleteAllContainers() + runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "test", "busybox", "top") + if out, _, err := runCommandWithOutput(runCmd); err != nil { + t.Fatalf("failed to run container: %v, output: %q", err, out) + } + cmd := exec.Command(dockerBinary, "inspect", "-f", "{{.HostConfig.RestartPolicy.Name}}", "test") + out, _, err := runCommandWithOutput(cmd) + if err != nil { + t.Fatalf("failed to inspect container: %v, output: %q", err, out) + } + out = strings.Trim(out, "\r\n") + if out != "no" { + t.Fatalf("Set default restart policy failed") + } + + logDone("run - set default restart policy success") +} + func TestRunRestartMaxRetries(t *testing.T) { defer deleteAllContainers() out, err := exec.Command(dockerBinary, "run", "-d", "--restart=on-failure:3", "busybox", "false").CombinedOutput() diff --git a/runconfig/parse.go b/runconfig/parse.go index fb81759b2d..bf87c42f94 100644 --- a/runconfig/parse.go +++ b/runconfig/parse.go @@ -66,7 +66,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe flNetMode = cmd.String([]string{"-net"}, "bridge", "Set the Network mode for the container") flMacAddress = cmd.String([]string{"-mac-address"}, "", "Container MAC address (e.g. 92:d0:c6:0a:29:33)") flIpcMode = cmd.String([]string{"-ipc"}, "", "IPC namespace to use") - flRestartPolicy = cmd.String([]string{"-restart"}, "", "Restart policy to apply when a container exits") + flRestartPolicy = cmd.String([]string{"-restart"}, "no", "Restart policy to apply when a container exits") flReadonlyRootfs = cmd.Bool([]string{"-read-only"}, false, "Mount the container's root filesystem as read only") )