Skip to content

Commit

Permalink
Add support for autodetected HOME from USER (if HOME is unset)
Browse files Browse the repository at this point in the history
Docker-DCO-1.1-Signed-off-by: Andrew Page <admwiggin@gmail.com> (github: tianon)
  • Loading branch information
tianon committed Jul 31, 2014
1 parent f4db398 commit 57b9467
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (b *buildFile) CmdFrom(name string) error {
b.config = image.Config
}
if b.config.Env == nil || len(b.config.Env) == 0 {
b.config.Env = append(b.config.Env, "HOME=/", "PATH="+daemon.DefaultPathEnv)
b.config.Env = append(b.config.Env, "PATH="+daemon.DefaultPathEnv)
}
// Process ONBUILD triggers if they exist
if nTriggers := len(b.config.OnBuild); nTriggers != 0 {
Expand Down
5 changes: 4 additions & 1 deletion daemon/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -1043,9 +1043,12 @@ func (container *Container) setupLinkedContainers() ([]string, error) {
func (container *Container) createDaemonEnvironment(linkedEnv []string) []string {
// Setup environment
env := []string{
"HOME=/",
"PATH=" + DefaultPathEnv,
"HOSTNAME=" + container.Config.Hostname,
// Note: we don't set HOME here because it'll get autoset intelligently
// based on the value of USER inside dockerinit, but only if it isn't
// set already (ie, that can be overridden by setting HOME via -e or ENV
// in a Dockerfile).
}
if container.Config.Tty {
env = append(env, "TERM=xterm")
Expand Down
2 changes: 1 addition & 1 deletion integration-cli/docker_cli_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ func TestBuildRelativeWorkdir(t *testing.T) {

func TestBuildEnv(t *testing.T) {
name := "testbuildenv"
expected := "[HOME=/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin PORT=2375]"
expected := "[PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin PORT=2375]"
defer deleteImages(name)
_, err := buildImage(name,
`FROM busybox
Expand Down
2 changes: 1 addition & 1 deletion integration-cli/docker_cli_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,13 +676,13 @@ func TestEnvironment(t *testing.T) {

goodEnv := []string{
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"HOME=/",
"HOSTNAME=testing",
"FALSE=true",
"TRUE=false",
"TRICKY=tri",
"cky",
"",
"HOME=/root",
}
sort.Strings(goodEnv)
if len(goodEnv) != len(actualEnv) {
Expand Down

0 comments on commit 57b9467

Please sign in to comment.