From 311a600f1912c0d2a30becffdecde6026ada2624 Mon Sep 17 00:00:00 2001 From: Lei Jitang Date: Tue, 10 Mar 2015 10:09:12 +0800 Subject: [PATCH] Set default restart policy name to 'no' Closes #10874 Signed-off-by: Lei Jitang --- docs/man/docker-create.1.md | 2 +- docs/man/docker-run.1.md | 2 +- docs/sources/reference/commandline/cli.md | 2 +- integration-cli/docker_cli_run_test.go | 19 +++++++++++++++++++ runconfig/parse.go | 2 +- 5 files changed, 23 insertions(+), 4 deletions(-) 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 7e3875afcc..c89627b70f 100644 --- a/docs/man/docker-run.1.md +++ b/docs/man/docker-run.1.md @@ -280,7 +280,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 da4daec88b..9bfdeea85e 100644 --- a/docs/sources/reference/commandline/cli.md +++ b/docs/sources/reference/commandline/cli.md @@ -799,7 +799,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 9869abe745..0a3fabeb5e 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -3178,6 +3178,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") )