From 7285c9a53a6a661e7ded4637d937f9d20dcf46c0 Mon Sep 17 00:00:00 2001 From: Shijiang Wei Date: Sun, 28 Feb 2016 01:38:26 +0800 Subject: [PATCH] validate log-opt when creating containers Signed-off-by: Shijiang Wei --- daemon/create.go | 6 ++++++ integration-cli/docker_cli_create_test.go | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/daemon/create.go b/daemon/create.go index 425c4344bb..b7b9001d63 100644 --- a/daemon/create.go +++ b/daemon/create.go @@ -5,6 +5,7 @@ import ( "github.com/Sirupsen/logrus" "github.com/docker/docker/container" + "github.com/docker/docker/daemon/logger" "github.com/docker/docker/image" "github.com/docker/docker/layer" "github.com/docker/docker/pkg/idtools" @@ -80,6 +81,11 @@ func (daemon *Daemon) create(params types.ContainerCreateConfig) (retC *containe } }() + logCfg := container.GetLogConfig(daemon.defaultLogConfig) + if err := logger.ValidateLogOpts(logCfg.Type, logCfg.Config); err != nil { + return nil, err + } + if err := daemon.setSecurityOptions(container, params.HostConfig); err != nil { return nil, err } diff --git a/integration-cli/docker_cli_create_test.go b/integration-cli/docker_cli_create_test.go index 81f3284368..ec7b8f4a58 100644 --- a/integration-cli/docker_cli_create_test.go +++ b/integration-cli/docker_cli_create_test.go @@ -440,3 +440,11 @@ func (s *DockerSuite) TestCreateWithWorkdir(c *check.C) { dockerCmd(c, "create", "--name", name, "-w", dir, "busybox") dockerCmd(c, "cp", fmt.Sprintf("%s:%s", name, dir), prefix+slash+"tmp") } + +func (s *DockerSuite) TestCreateWithInvalidLogOpts(c *check.C) { + name := "test-invalidate-log-opts" + _, _, err := dockerCmdWithError("create", "--name", name, "--log-opt", "invalid=true") + c.Assert(err, checker.NotNil) + out, _ := dockerCmd(c, "ps", "-a") + c.Assert(out, checker.Not(checker.Contains), name) +}