Windows: Set default directory
Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
parent
e764e0215e
commit
c2d183426b
2 changed files with 25 additions and 5 deletions
|
@ -56,6 +56,16 @@ func (daemon *Daemon) createSpec(c *container.Container) (*libcontainerd.Spec, e
|
|||
s.Process.Args = escapeArgs(s.Process.Args)
|
||||
}
|
||||
s.Process.Cwd = c.Config.WorkingDir
|
||||
if len(s.Process.Cwd) == 0 {
|
||||
// We default to C:\ to workaround the oddity of the case that the
|
||||
// default directory for cmd running as LocalSystem (or
|
||||
// ContainerAdministrator) is c:\windows\system32. Hence docker run
|
||||
// <image> cmd will by default end in c:\windows\system32, rather
|
||||
// than 'root' (/) on Linux. The oddity is that if you have a dockerfile
|
||||
// which has no WORKDIR and has a COPY file ., . will be interpreted
|
||||
// as c:\. Hence, setting it to default of c:\ makes for consistency.
|
||||
s.Process.Cwd = `C:\`
|
||||
}
|
||||
s.Process.Env = c.CreateDaemonEnvironment(linkedEnv)
|
||||
s.Process.InitialConsoleSize = c.HostConfig.ConsoleSize
|
||||
s.Process.Terminal = c.Config.Tty
|
||||
|
|
|
@ -2074,8 +2074,18 @@ func (s *DockerSuite) TestBuildRelativeWorkdir(c *check.C) {
|
|||
expected4 string
|
||||
expectedFinal string
|
||||
)
|
||||
// TODO Windows: The expectedFinal needs fixing to match Windows
|
||||
// filepath semantics. However, this is a non-trivial change. @jhowardmsft
|
||||
// Short story - need to make the configuration file platform semantically
|
||||
// consistent, so even if `WORKDIR /test2/test3` is specified in a Dockerfile,
|
||||
// the configuration should be stored as C:\test2\test3. Something similar to
|
||||
// if runtime.GOOS == "windows" && len(workdir) > 2 && string(workdir[0]) == `\` {
|
||||
// workdir = "C:" + workdir
|
||||
// }
|
||||
// in builder\dockerfile\dispatchers.go, function workdir(), but also
|
||||
// ironing out all other cases where this causes other failures.
|
||||
if daemonPlatform == "windows" {
|
||||
expected1 = `C:/Windows/system32`
|
||||
expected1 = `C:/`
|
||||
expected2 = `C:/test1`
|
||||
expected3 = `C:/test2`
|
||||
expected4 = `C:/test2/test3`
|
||||
|
@ -2090,13 +2100,13 @@ func (s *DockerSuite) TestBuildRelativeWorkdir(c *check.C) {
|
|||
|
||||
_, err := buildImage(name,
|
||||
`FROM busybox
|
||||
RUN sh -c "[ "$PWD" = '`+expected1+`' ]"
|
||||
RUN sh -c "[ "$PWD" = "`+expected1+`" ]"
|
||||
WORKDIR test1
|
||||
RUN sh -c "[ "$PWD" = '`+expected2+`' ]"
|
||||
RUN sh -c "[ "$PWD" = "`+expected2+`" ]"
|
||||
WORKDIR /test2
|
||||
RUN sh -c "[ "$PWD" = '`+expected3+`' ]"
|
||||
RUN sh -c "[ "$PWD" = "`+expected3+`" ]"
|
||||
WORKDIR test3
|
||||
RUN sh -c "[ "$PWD" = '`+expected4+`' ]"`,
|
||||
RUN sh -c "[ "$PWD" = "`+expected4+`" ]"`,
|
||||
true)
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
|
|
Loading…
Reference in a new issue