1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Fix missing hostname and links in exec env

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi 2016-09-28 15:21:33 -07:00
parent 1d669d82c1
commit e981459609
7 changed files with 19 additions and 17 deletions

View file

@ -28,7 +28,7 @@ type ExitStatus struct {
}
// CreateDaemonEnvironment creates a new environment variable slice for this container.
func (container *Container) CreateDaemonEnvironment(linkedEnv []string) []string {
func (container *Container) CreateDaemonEnvironment(_ bool, linkedEnv []string) []string {
return nil
}

View file

@ -52,13 +52,13 @@ type ExitStatus struct {
// environment variables related to links.
// Sets PATH, HOSTNAME and if container.Config.Tty is set: TERM.
// The defaults set here do not override the values in container.Config.Env
func (container *Container) CreateDaemonEnvironment(linkedEnv []string) []string {
func (container *Container) CreateDaemonEnvironment(tty bool, linkedEnv []string) []string {
// Setup environment
env := []string{
"PATH=" + system.DefaultPathEnv,
"HOSTNAME=" + container.Config.Hostname,
}
if container.Config.Tty {
if tty {
env = append(env, "TERM=xterm")
}
env = append(env, linkedEnv...)

View file

@ -30,7 +30,7 @@ type ExitStatus struct {
}
// CreateDaemonEnvironment creates a new environment variable slice for this container.
func (container *Container) CreateDaemonEnvironment(linkedEnv []string) []string {
func (container *Container) CreateDaemonEnvironment(_ bool, linkedEnv []string) []string {
// because the env on the container can override certain default values
// we need to replace the 'env' keys where they match and append anything
// else.

View file

@ -3,7 +3,6 @@ package daemon
import (
"fmt"
"io"
"runtime"
"strings"
"time"
@ -18,7 +17,6 @@ import (
"github.com/docker/docker/libcontainerd"
"github.com/docker/docker/pkg/pools"
"github.com/docker/docker/pkg/signal"
"github.com/docker/docker/pkg/system"
"github.com/docker/docker/pkg/term"
"github.com/docker/docker/utils"
)
@ -125,16 +123,11 @@ func (d *Daemon) ContainerExecCreate(name string, config *types.ExecConfig) (str
execConfig.Privileged = config.Privileged
execConfig.User = config.User
// On Windows, don't default the path, let the platform do it. Also TERM isn't meaningful
if runtime.GOOS != "windows" {
execConfig.Env = []string{
"PATH=" + system.DefaultPathEnv,
}
if config.Tty {
execConfig.Env = append(execConfig.Env, "TERM=xterm")
}
linkedEnv, err := d.setupLinkedContainers(container)
if err != nil {
return "", err
}
execConfig.Env = utils.ReplaceOrAppendEnvValues(execConfig.Env, container.Config.Env)
execConfig.Env = utils.ReplaceOrAppendEnvValues(container.CreateDaemonEnvironment(config.Tty, linkedEnv), execConfig.Env)
if len(execConfig.User) == 0 {
execConfig.User = container.Config.User
}

View file

@ -616,7 +616,7 @@ func (daemon *Daemon) populateCommonSpec(s *specs.Spec, c *container.Container)
}
}
s.Process.Cwd = cwd
s.Process.Env = c.CreateDaemonEnvironment(linkedEnv)
s.Process.Env = c.CreateDaemonEnvironment(c.Config.Tty, linkedEnv)
s.Process.Terminal = c.Config.Tty
s.Hostname = c.FullHostname()

View file

@ -59,7 +59,7 @@ func (daemon *Daemon) createSpec(c *container.Container) (*libcontainerd.Spec, e
// as c:\. Hence, setting it to default of c:\ makes for consistency.
s.Process.Cwd = `C:\`
}
s.Process.Env = c.CreateDaemonEnvironment(linkedEnv)
s.Process.Env = c.CreateDaemonEnvironment(c.Config.Tty, linkedEnv)
s.Process.ConsoleSize.Height = c.HostConfig.ConsoleSize[0]
s.Process.ConsoleSize.Width = c.HostConfig.ConsoleSize[1]
s.Process.Terminal = c.Config.Tty

View file

@ -520,3 +520,12 @@ func (s *DockerSuite) TestExecWindowsPathNotWiped(c *check.C) {
out = strings.ToLower(strings.Trim(out, "\r\n"))
c.Assert(out, checker.Contains, `windowspowershell\v1.0`)
}
func (s *DockerSuite) TestExecEnvLinksHost(c *check.C) {
testRequires(c, DaemonIsLinux)
runSleepingContainer(c, "-d", "--name", "foo")
runSleepingContainer(c, "-d", "--link", "foo:db", "--hostname", "myhost", "--name", "bar")
out, _ := dockerCmd(c, "exec", "bar", "env")
c.Assert(out, checker.Contains, "HOSTNAME=myhost")
c.Assert(out, checker.Contains, "DB_NAME=/bar/db")
}