From 5ae8c7a98592f83a31f3f45fc22728e45e95626c Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Sun, 14 Jul 2013 18:23:20 -0900 Subject: [PATCH] Copy VolumesRW values when using --volumes-from Fixes #1201 --- container.go | 3 +++ container_test.go | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/container.go b/container.go index 2791289269..c714e9f0e1 100644 --- a/container.go +++ b/container.go @@ -597,6 +597,9 @@ func (container *Container) Start(hostConfig *HostConfig) error { return nil } container.Volumes[volPath] = id + if isRW, exists := c.VolumesRW[volPath]; exists { + container.VolumesRW[volPath] = isRW + } } } diff --git a/container_test.go b/container_test.go index e7f6818eb6..3402d39840 100644 --- a/container_test.go +++ b/container_test.go @@ -1229,3 +1229,57 @@ func TestBindMounts(t *testing.T) { } } + +// Test that VolumesRW values are copied to the new container. Regression test for #1201 +func TestVolumesFromReadonlyMount(t *testing.T) { + runtime := mkRuntime(t) + defer nuke(runtime) + container, err := NewBuilder(runtime).Create( + &Config{ + Image: GetTestImage(runtime).ID, + Cmd: []string{"/bin/echo", "-n", "foobar"}, + Volumes: map[string]struct{}{"/test": {}}, + }, + ) + if err != nil { + t.Fatal(err) + } + defer runtime.Destroy(container) + _, err = container.Output() + if err != nil { + t.Fatal(err) + } + if !container.VolumesRW["/test"] { + t.Fail() + } + + container2, err := NewBuilder(runtime).Create( + &Config{ + Image: GetTestImage(runtime).ID, + Cmd: []string{"/bin/echo", "-n", "foobar"}, + VolumesFrom: container.ID, + }, + ) + if err != nil { + t.Fatal(err) + } + defer runtime.Destroy(container2) + + _, err = container2.Output() + if err != nil { + t.Fatal(err) + } + + if container.Volumes["/test"] != container2.Volumes["/test"] { + t.Fail() + } + + actual, exists := container2.VolumesRW["/test"] + if !exists { + t.Fail() + } + + if container.VolumesRW["/test"] != actual { + t.Fail() + } +}