diff --git a/execdriver/native/default_template.go b/execdriver/native/default_template.go index f202fd2529..7426e678e8 100644 --- a/execdriver/native/default_template.go +++ b/execdriver/native/default_template.go @@ -1,10 +1,48 @@ package native import ( + "fmt" + "github.com/dotcloud/docker/execdriver" "github.com/dotcloud/docker/pkg/cgroups" "github.com/dotcloud/docker/pkg/libcontainer" ) +// createContainer populates and configrues the container type with the +// data provided by the execdriver.Command +func createContainer(c *execdriver.Command) *libcontainer.Container { + container := getDefaultTemplate() + + container.Hostname = getEnv("HOSTNAME", c.Env) + container.Tty = c.Tty + container.User = c.User + container.WorkingDir = c.WorkingDir + container.Env = c.Env + + if c.Network != nil { + container.Network = &libcontainer.Network{ + Mtu: c.Network.Mtu, + Address: fmt.Sprintf("%s/%d", c.Network.IPAddress, c.Network.IPPrefixLen), + Gateway: c.Network.Gateway, + Type: "veth", + Context: libcontainer.Context{ + "prefix": "dock", + "bridge": c.Network.Bridge, + }, + } + } + container.Cgroups.Name = c.ID + if c.Privileged { + container.Capabilities = nil + container.Cgroups.DeviceAccess = true + } + if c.Resources != nil { + container.Cgroups.CpuShares = c.Resources.CpuShares + container.Cgroups.Memory = c.Resources.Memory + container.Cgroups.MemorySwap = c.Resources.MemorySwap + } + return container +} + // getDefaultTemplate returns the docker default for // the libcontainer configuration file func getDefaultTemplate() *libcontainer.Container { diff --git a/execdriver/native/driver.go b/execdriver/native/driver.go index 31b5ae290c..a10125c120 100644 --- a/execdriver/native/driver.go +++ b/execdriver/native/driver.go @@ -231,39 +231,3 @@ func (d *dockerStateWriter) WritePid(pid int) error { func (d *dockerStateWriter) DeletePid() error { return d.dsw.DeletePid() } - -func createContainer(c *execdriver.Command) *libcontainer.Container { - container := getDefaultTemplate() - - container.Hostname = getEnv("HOSTNAME", c.Env) - container.Tty = c.Tty - container.User = c.User - container.WorkingDir = c.WorkingDir - container.Env = c.Env - - container.Env = append(container.Env, "container=docker") - - if c.Network != nil { - container.Network = &libcontainer.Network{ - Mtu: c.Network.Mtu, - Address: fmt.Sprintf("%s/%d", c.Network.IPAddress, c.Network.IPPrefixLen), - Gateway: c.Network.Gateway, - Type: "veth", - Context: libcontainer.Context{ - "prefix": "dock", - "bridge": c.Network.Bridge, - }, - } - } - container.Cgroups.Name = c.ID - if c.Privileged { - container.Capabilities = nil - container.Cgroups.DeviceAccess = true - } - if c.Resources != nil { - container.Cgroups.CpuShares = c.Resources.CpuShares - container.Cgroups.Memory = c.Resources.Memory - container.Cgroups.MemorySwap = c.Resources.MemorySwap - } - return container -} diff --git a/integration/container_test.go b/integration/container_test.go index 8e4314f456..4efb95a2a1 100644 --- a/integration/container_test.go +++ b/integration/container_test.go @@ -1044,7 +1044,6 @@ func TestEnv(t *testing.T) { goodEnv := []string{ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "HOME=/", - "container=docker", "HOSTNAME=" + utils.TruncateID(container.ID), "FALSE=true", "TRUE=false", diff --git a/integration/utils_test.go b/integration/utils_test.go index fc66e8bcbd..2d8a3e709e 100644 --- a/integration/utils_test.go +++ b/integration/utils_test.go @@ -190,6 +190,7 @@ func newTestEngine(t utils.Fataler, autorestart bool, root string) *engine.Engin job := eng.Job("initserver") job.Setenv("Root", root) job.SetenvBool("AutoRestart", autorestart) + job.Setenv("ExecDriver", "native") // TestGetEnabledCors and TestOptionsRoute require EnableCors=true job.SetenvBool("EnableCors", true) if err := job.Run(); err != nil { diff --git a/runtime.go b/runtime.go index 1003c35d5d..1a95ad6270 100644 --- a/runtime.go +++ b/runtime.go @@ -713,7 +713,7 @@ func NewRuntimeFromDirectory(config *DaemonConfig, eng *engine.Engine) (*Runtime case "native": ed, err = native.NewDriver(config.Root) default: - return nil, fmt.Errorf("unknow exec driver %s", config.ExecDriver) + return nil, fmt.Errorf("unknown exec driver %s", config.ExecDriver) } if err != nil { return nil, err