diff --git a/daemon/container.go b/daemon/container.go index 123eca0263..7313804326 100644 --- a/daemon/container.go +++ b/daemon/container.go @@ -168,19 +168,6 @@ func (container *Container) WriteHostConfig() (err error) { return ioutil.WriteFile(container.hostConfigPath(), data, 0666) } -func (container *Container) generateEnvConfig(env []string) error { - data, err := json.Marshal(env) - if err != nil { - return err - } - p, err := container.EnvConfigPath() - if err != nil { - return err - } - ioutil.WriteFile(p, data, 0600) - return nil -} - func (container *Container) Attach(stdin io.ReadCloser, stdinCloser io.Closer, stdout io.Writer, stderr io.Writer) chan error { var cStdout, cStderr io.ReadCloser @@ -422,15 +409,10 @@ func (container *Container) Start() (err error) { if err != nil { return err } - env := container.createDaemonEnvironment(linkedEnv) - // TODO: This is only needed for lxc so we should look for a way to - // remove this dep - if err := container.generateEnvConfig(env); err != nil { - return err - } if err := container.setupWorkingDirectory(); err != nil { return err } + env := container.createDaemonEnvironment(linkedEnv) if err := populateCommand(container, env); err != nil { return err } @@ -851,22 +833,6 @@ func (container *Container) jsonPath() string { return path.Join(container.root, "config.json") } -func (container *Container) EnvConfigPath() (string, error) { - p := path.Join(container.root, "config.env") - if _, err := os.Stat(p); err != nil { - if os.IsNotExist(err) { - f, err := os.Create(p) - if err != nil { - return "", err - } - f.Close() - } else { - return "", err - } - } - return p, nil -} - // This method must be exported to be used from the lxc template // This directory is only usable when the container is running func (container *Container) RootfsPath() string { diff --git a/daemon/execdriver/lxc/driver.go b/daemon/execdriver/lxc/driver.go index 2c06211c0d..d787d8d873 100644 --- a/daemon/execdriver/lxc/driver.go +++ b/daemon/execdriver/lxc/driver.go @@ -1,6 +1,7 @@ package lxc import ( + "encoding/json" "fmt" "io/ioutil" "log" @@ -85,6 +86,9 @@ func (d *driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, startCallba if err := execdriver.SetTerminal(c, pipes); err != nil { return -1, err } + if err := d.generateEnvConfig(c); err != nil { + return -1, err + } configPath, err := d.generateLXCConfig(c) if err != nil { return -1, err @@ -416,3 +420,14 @@ func (d *driver) generateLXCConfig(c *execdriver.Command) (string, error) { } return root, nil } + +func (d *driver) generateEnvConfig(c *execdriver.Command) error { + data, err := json.Marshal(c.Env) + if err != nil { + return err + } + p := path.Join(d.root, "containers", c.ID, "config.env") + c.Mounts = append(c.Mounts, execdriver.Mount{p, "/.dockerenv", false, true}) + + return ioutil.WriteFile(p, data, 0600) +} diff --git a/daemon/volumes.go b/daemon/volumes.go index a6570845bf..a15e3084b2 100644 --- a/daemon/volumes.go +++ b/daemon/volumes.go @@ -2,14 +2,15 @@ package daemon import ( "fmt" - "github.com/dotcloud/docker/archive" - "github.com/dotcloud/docker/daemon/execdriver" - "github.com/dotcloud/docker/utils" "io/ioutil" "os" "path/filepath" "strings" "syscall" + + "github.com/dotcloud/docker/archive" + "github.com/dotcloud/docker/daemon/execdriver" + "github.com/dotcloud/docker/utils" ) type BindMap struct { @@ -34,14 +35,8 @@ func prepareVolumesForContainer(container *Container) error { } func setupMountsForContainer(container *Container) error { - envPath, err := container.EnvConfigPath() - if err != nil { - return err - } - mounts := []execdriver.Mount{ {container.daemon.sysInitPath, "/.dockerinit", false, true}, - {envPath, "/.dockerenv", false, true}, {container.ResolvConfPath, "/etc/resolv.conf", false, true}, }