Browse code

Create the working directory on container creation

if create a container with -w to specify the working directory and
the directory does not exist in the container rootfs, the directory
will be created until the container start. It make docker export of
a created container and a running container inconsistent.

Signed-off-by: Lei Jitang <leijitang@huawei.com>

Lei Jitang authored on 2016/01/08 13:11:21
Showing 3 changed files
... ...
@@ -22,6 +22,10 @@ func (daemon *Daemon) createContainerPlatformSpecificSettings(container *contain
22 22
 	}
23 23
 	defer daemon.Unmount(container)
24 24
 
25
+	if err := container.SetupWorkingDirectory(); err != nil {
26
+		return err
27
+	}
28
+
25 29
 	for spec := range config.Volumes {
26 30
 		name := stringid.GenerateNonCryptoID()
27 31
 		destination := filepath.Clean(spec)
... ...
@@ -6152,8 +6152,8 @@ func (s *DockerSuite) TestBuildBuildTimeArgExpansion(c *check.C) {
6152 6152
 	if err != nil {
6153 6153
 		c.Fatal(err)
6154 6154
 	}
6155
-	if res != wdVal {
6156
-		c.Fatalf("Config.WorkingDir value mismatch. Expected: %s, got: %s", wdVal, res)
6155
+	if res != filepath.Clean(wdVal) {
6156
+		c.Fatalf("Config.WorkingDir value mismatch. Expected: %s, got: %s", filepath.Clean(wdVal), res)
6157 6157
 	}
6158 6158
 
6159 6159
 	err = inspectFieldAndMarshall(imgName, "Config.Env", &resArr)
... ...
@@ -415,3 +415,11 @@ func (s *DockerSuite) TestCreateStopSignal(c *check.C) {
415 415
 	c.Assert(res, checker.Contains, "9")
416 416
 
417 417
 }
418
+
419
+func (s *DockerSuite) TestCreateWithWorkdir(c *check.C) {
420
+	testRequires(c, DaemonIsLinux)
421
+	name := "foo"
422
+	dir := "/home/foo/bar"
423
+	dockerCmd(c, "create", "--name", name, "-w", dir, "busybox")
424
+	dockerCmd(c, "cp", fmt.Sprintf("%s:%s", name, dir), "/tmp")
425
+}