Fix image's CMD
after WORKDIR
in Dockerfile
This fix tries to fix 29667 where image's `CMD` is modified
after `WORKDIR` in Dockerfile.
The value of `b.runConfig.Cmd` was modified in the processing
of `WORKDIR`, in order to fix 28902. However, the same
`b.runConfig.Cmd` is passed to `commit()`.
This fix restored the `b.runConfig.Cmd` before `commit()`
the image for `WORKDIR`.
A test has been added.
This fix fixes 29667.
This fix is related to 28902, 28909, 28514.
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
(cherry picked from commit 0836023847
)
Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
parent
ea00b14170
commit
e2b04a7818
2 changed files with 45 additions and 5 deletions
|
@ -297,17 +297,17 @@ func workdir(b *Builder, args []string, attributes map[string]bool, original str
|
|||
}
|
||||
b.runConfig.Image = b.image
|
||||
|
||||
cmd := b.runConfig.Cmd
|
||||
b.runConfig.Cmd = strslice.StrSlice(append(getShell(b.runConfig), fmt.Sprintf("#(nop) WORKDIR %s", b.runConfig.WorkingDir)))
|
||||
defer func(cmd strslice.StrSlice) { b.runConfig.Cmd = cmd }(cmd)
|
||||
|
||||
if hit, err := b.probeCache(); err != nil {
|
||||
return err
|
||||
} else if hit {
|
||||
return nil
|
||||
}
|
||||
|
||||
container, err := b.docker.ContainerCreate(types.ContainerCreateConfig{Config: b.runConfig})
|
||||
// Actually copy the struct
|
||||
workdirConfig := *b.runConfig
|
||||
workdirConfig.Cmd = strslice.StrSlice(append(getShell(b.runConfig), fmt.Sprintf("#(nop) WORKDIR %s", b.runConfig.WorkingDir)))
|
||||
|
||||
container, err := b.docker.ContainerCreate(types.ContainerCreateConfig{Config: &workdirConfig})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -7357,3 +7357,43 @@ func (s *DockerSuite) TestBuildWindowsEnvCaseInsensitive(c *check.C) {
|
|||
c.Fatalf("Case insensitive environment variables on Windows failed. Got %s", res)
|
||||
}
|
||||
}
|
||||
|
||||
// Test case for 29667
|
||||
func (s *DockerSuite) TestBuildWorkdirImageCmd(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
image := "testworkdirimagecmd"
|
||||
dockerfile := `
|
||||
FROM busybox
|
||||
WORKDIR /foo/bar
|
||||
`
|
||||
out, err := buildImage(image, dockerfile, true)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("Output: %s", out))
|
||||
|
||||
out, _ = dockerCmd(c, "inspect", "--format", "{{ json .Config.Cmd }}", image)
|
||||
c.Assert(strings.TrimSpace(out), checker.Equals, `["sh"]`)
|
||||
|
||||
image = "testworkdirlabelimagecmd"
|
||||
dockerfile = `
|
||||
FROM busybox
|
||||
WORKDIR /foo/bar
|
||||
LABEL a=b
|
||||
`
|
||||
out, err = buildImage(image, dockerfile, true)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("Output: %s", out))
|
||||
|
||||
out, _ = dockerCmd(c, "inspect", "--format", "{{ json .Config.Cmd }}", image)
|
||||
c.Assert(strings.TrimSpace(out), checker.Equals, `["sh"]`)
|
||||
}
|
||||
|
||||
// Test case for 28902/28090
|
||||
func (s *DockerSuite) TestBuildWorkdirCmd(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
dockerFile := `
|
||||
FROM golang:1.7-alpine
|
||||
WORKDIR /
|
||||
`
|
||||
_, err := buildImage("testbuildworkdircmd", dockerFile, false)
|
||||
c.Assert(err, checker.IsNil)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue