Skip to content

Commit ed387fb

Browse files
committed
Fix CopyData in Bind Mount and add test
CopyData is an action which should be enabled only in mount volumes and images. For example: [root@hostname]# pouch run -it --name test2 -v /home/baijia.wr/volume/:/var/ docker.io/library/busybox:latest ls /var/ spool www [root@hostname]# ls /home/baijia.wr/volume/ spool www Without this patch, data is copied form container's dir "/var/" to host's dir "/home/baijia.wr/volume/", that is unexpected. So CopyData should be disabled in bind mount. Signed-off-by: Wang Rui <[email protected]>
1 parent aa61bb1 commit ed387fb

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

daemon/mgr/container_storage.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ func (mgr *ContainerManager) getMountPointFromBinds(ctx context.Context, c *Cont
207207
mp.Named = false
208208
mp.Driver = ""
209209
}
210+
} else {
211+
mp.CopyData = false
210212
}
211213

212214
c.Mounts = append(c.Mounts, mp)

test/cli_run_volume_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,34 @@ func (suite *PouchRunVolumeSuite) TestRunWithTmpFSVolume(c *check.C) {
7575
c.Assert(strings.Contains(res.Stdout(), "1.0M"), check.Equals, true)
7676
}
7777

78+
//TestRunWithHostFileVolume tests binds copying data
79+
//Pouch volumes should copy data, but host bind mount should not.
80+
func (suite *PouchRunVolumeSuite) TestRunWithVolumeCopyData(c *check.C) {
81+
volumeName := "volume-test-copydata"
82+
hostdir := "/tmp/bind-test-copydata"
83+
containerName1 := "copydata-test-1"
84+
containerName2 := "copydata-test-2"
85+
86+
// create volume
87+
command.PouchRun("volume", "create", "-n", volumeName).Assert(c, icmd.Success)
88+
defer func() {
89+
command.PouchRun("volume", "rm", volumeName).Assert(c, icmd.Success)
90+
}()
91+
92+
command.PouchRun("run", "-t", "-v", volumeName+":/var", "--name", containerName1, busyboxImage, "ls", "/var").Assert(c, icmd.Success)
93+
defer DelContainerForceMultyTime(c, containerName1)
94+
output1 := icmd.RunCommand("ls", DefaultVolumeMountPath+"/"+volumeName).Stdout()
95+
lines := strings.Split(output1, "\n")
96+
c.Assert(lines[0], check.Equals, "spool")
97+
c.Assert(lines[1], check.Equals, "www")
98+
99+
command.PouchRun("run", "-t", "-v", hostdir+":/var", "--name", containerName2, busyboxImage, "ls", "/var").Assert(c, icmd.Success)
100+
defer DelContainerForceMultyTime(c, containerName2)
101+
defer icmd.RunCommand("rm", "-rf", hostdir)
102+
output2 := icmd.RunCommand("ls", hostdir).Stdout()
103+
c.Assert(output2, check.Equals, "")
104+
}
105+
78106
// TestRunWithHostFileVolume tests binding a host file as a volume into container.
79107
// fixes https://github.com/alibaba/pouch/issues/813
80108
func (suite *PouchRunVolumeSuite) TestRunWithHostFileVolume(c *check.C) {

0 commit comments

Comments
 (0)