Signed-off-by: John Howard <jhoward@microsoft.com>
| ... | ... |
@@ -56,6 +56,16 @@ func (daemon *Daemon) createSpec(c *container.Container) (*libcontainerd.Spec, e |
| 56 | 56 |
s.Process.Args = escapeArgs(s.Process.Args) |
| 57 | 57 |
} |
| 58 | 58 |
s.Process.Cwd = c.Config.WorkingDir |
| 59 |
+ if len(s.Process.Cwd) == 0 {
|
|
| 60 |
+ // We default to C:\ to workaround the oddity of the case that the |
|
| 61 |
+ // default directory for cmd running as LocalSystem (or |
|
| 62 |
+ // ContainerAdministrator) is c:\windows\system32. Hence docker run |
|
| 63 |
+ // <image> cmd will by default end in c:\windows\system32, rather |
|
| 64 |
+ // than 'root' (/) on Linux. The oddity is that if you have a dockerfile |
|
| 65 |
+ // which has no WORKDIR and has a COPY file ., . will be interpreted |
|
| 66 |
+ // as c:\. Hence, setting it to default of c:\ makes for consistency. |
|
| 67 |
+ s.Process.Cwd = `C:\` |
|
| 68 |
+ } |
|
| 59 | 69 |
s.Process.Env = c.CreateDaemonEnvironment(linkedEnv) |
| 60 | 70 |
s.Process.InitialConsoleSize = c.HostConfig.ConsoleSize |
| 61 | 71 |
s.Process.Terminal = c.Config.Tty |
| ... | ... |
@@ -2074,8 +2074,18 @@ func (s *DockerSuite) TestBuildRelativeWorkdir(c *check.C) {
|
| 2074 | 2074 |
expected4 string |
| 2075 | 2075 |
expectedFinal string |
| 2076 | 2076 |
) |
| 2077 |
+ // TODO Windows: The expectedFinal needs fixing to match Windows |
|
| 2078 |
+ // filepath semantics. However, this is a non-trivial change. @jhowardmsft |
|
| 2079 |
+ // Short story - need to make the configuration file platform semantically |
|
| 2080 |
+ // consistent, so even if `WORKDIR /test2/test3` is specified in a Dockerfile, |
|
| 2081 |
+ // the configuration should be stored as C:\test2\test3. Something similar to |
|
| 2082 |
+ // if runtime.GOOS == "windows" && len(workdir) > 2 && string(workdir[0]) == `\` {
|
|
| 2083 |
+ // workdir = "C:" + workdir |
|
| 2084 |
+ // } |
|
| 2085 |
+ // in builder\dockerfile\dispatchers.go, function workdir(), but also |
|
| 2086 |
+ // ironing out all other cases where this causes other failures. |
|
| 2077 | 2087 |
if daemonPlatform == "windows" {
|
| 2078 |
- expected1 = `C:/Windows/system32` |
|
| 2088 |
+ expected1 = `C:/` |
|
| 2079 | 2089 |
expected2 = `C:/test1` |
| 2080 | 2090 |
expected3 = `C:/test2` |
| 2081 | 2091 |
expected4 = `C:/test2/test3` |
| ... | ... |
@@ -2090,13 +2100,13 @@ func (s *DockerSuite) TestBuildRelativeWorkdir(c *check.C) {
|
| 2090 | 2090 |
|
| 2091 | 2091 |
_, err := buildImage(name, |
| 2092 | 2092 |
`FROM busybox |
| 2093 |
- RUN sh -c "[ "$PWD" = '`+expected1+`' ]" |
|
| 2093 |
+ RUN sh -c "[ "$PWD" = "`+expected1+`" ]" |
|
| 2094 | 2094 |
WORKDIR test1 |
| 2095 |
- RUN sh -c "[ "$PWD" = '`+expected2+`' ]" |
|
| 2095 |
+ RUN sh -c "[ "$PWD" = "`+expected2+`" ]" |
|
| 2096 | 2096 |
WORKDIR /test2 |
| 2097 |
- RUN sh -c "[ "$PWD" = '`+expected3+`' ]" |
|
| 2097 |
+ RUN sh -c "[ "$PWD" = "`+expected3+`" ]" |
|
| 2098 | 2098 |
WORKDIR test3 |
| 2099 |
- RUN sh -c "[ "$PWD" = '`+expected4+`' ]"`, |
|
| 2099 |
+ RUN sh -c "[ "$PWD" = "`+expected4+`" ]"`, |
|
| 2100 | 2100 |
true) |
| 2101 | 2101 |
if err != nil {
|
| 2102 | 2102 |
c.Fatal(err) |