From 4bdf86ad9b57e4f1f1f9d6c69746deda0f7e168d Mon Sep 17 00:00:00 2001 From: Qiang Huang Date: Sat, 23 May 2015 07:15:14 +0800 Subject: [PATCH] Don't check running container at create time We should let user create container even if the container he wants join is not running, that check should be done at start time. In this case, the running check is done by getIpcContainer() when we start container. Signed-off-by: Qiang Huang Upstream-commit: 84aae5a22605f8849e7335157afeca471b563a29 Component: engine --- components/engine/daemon/create.go | 3 --- .../integration-cli/docker_cli_create_test.go | 18 ++++++++++++++++++ .../integration-cli/docker_cli_run_test.go | 17 +++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/components/engine/daemon/create.go b/components/engine/daemon/create.go index d8addd3a99..c9dfa8e4d8 100644 --- a/components/engine/daemon/create.go +++ b/components/engine/daemon/create.go @@ -114,9 +114,6 @@ func (daemon *Daemon) GenerateSecurityOpt(ipcMode runconfig.IpcMode, pidMode run if err != nil { return nil, err } - if !c.IsRunning() { - return nil, fmt.Errorf("cannot join IPC of a non running container: %s", ipcContainer) - } return label.DupSecOpt(c.ProcessLabel), nil } diff --git a/components/engine/integration-cli/docker_cli_create_test.go b/components/engine/integration-cli/docker_cli_create_test.go index 14d320d851..019ea97fc6 100644 --- a/components/engine/integration-cli/docker_cli_create_test.go +++ b/components/engine/integration-cli/docker_cli_create_test.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "fmt" "os" "os/exec" "reflect" @@ -323,3 +324,20 @@ func (s *DockerSuite) TestCreateRM(c *check.C) { c.Fatalf("Failed to rm -f container:%s\n%s", out, err) } } + +func (s *DockerSuite) TestCreateModeIpcContainer(c *check.C) { + testRequires(c, SameHostDaemon) + + cmd := exec.Command(dockerBinary, "create", "busybox") + out, _, err := runCommandWithOutput(cmd) + if err != nil { + c.Fatal(err, out) + } + id := strings.TrimSpace(out) + + cmd = exec.Command(dockerBinary, "create", fmt.Sprintf("--ipc=container:%s", id), "busybox") + out, _, err = runCommandWithOutput(cmd) + if err != nil { + c.Fatalf("Create container with ipc mode container should success with non running container: %s\n%s", out, err) + } +} diff --git a/components/engine/integration-cli/docker_cli_run_test.go b/components/engine/integration-cli/docker_cli_run_test.go index 0b067b9785..5a68ba234f 100644 --- a/components/engine/integration-cli/docker_cli_run_test.go +++ b/components/engine/integration-cli/docker_cli_run_test.go @@ -2659,6 +2659,23 @@ func (s *DockerSuite) TestRunModeIpcContainerNotExists(c *check.C) { } } +func (s *DockerSuite) TestRunModeIpcContainerNotRunning(c *check.C) { + testRequires(c, SameHostDaemon) + + cmd := exec.Command(dockerBinary, "create", "busybox") + out, _, err := runCommandWithOutput(cmd) + if err != nil { + c.Fatal(err, out) + } + id := strings.TrimSpace(out) + + cmd = exec.Command(dockerBinary, "run", fmt.Sprintf("--ipc=container:%s", id), "busybox") + out, _, err = runCommandWithOutput(cmd) + if err == nil { + c.Fatalf("Run container with ipc mode container should fail with non running container: %s\n%s", out, err) + } +} + func (s *DockerSuite) TestContainerNetworkMode(c *check.C) { testRequires(c, SameHostDaemon)