Initialize volumes when container is created
| ... | ... |
@@ -100,6 +100,13 @@ func (daemon *Daemon) Create(config *runconfig.Config, hostConfig *runconfig.Hos |
| 100 | 100 |
return nil, nil, err |
| 101 | 101 |
} |
| 102 | 102 |
} |
| 103 |
+ if err := container.Mount(); err != nil {
|
|
| 104 |
+ return nil, nil, err |
|
| 105 |
+ } |
|
| 106 |
+ defer container.Unmount() |
|
| 107 |
+ if err := container.prepareVolumes(); err != nil {
|
|
| 108 |
+ return nil, nil, err |
|
| 109 |
+ } |
|
| 103 | 110 |
if err := container.ToDisk(); err != nil {
|
| 104 | 111 |
return nil, nil, err |
| 105 | 112 |
} |
| ... | ... |
@@ -2,6 +2,7 @@ package main |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"encoding/json" |
| 5 |
+ "os" |
|
| 5 | 6 |
"os/exec" |
| 6 | 7 |
"testing" |
| 7 | 8 |
"time" |
| ... | ... |
@@ -125,3 +126,21 @@ func TestCreateEchoStdout(t *testing.T) {
|
| 125 | 125 |
|
| 126 | 126 |
logDone("create - echo test123")
|
| 127 | 127 |
} |
| 128 |
+ |
|
| 129 |
+func TestCreateVolumesCreated(t *testing.T) {
|
|
| 130 |
+ name := "test_create_volume" |
|
| 131 |
+ cmd(t, "create", "--name", name, "-v", "/foo", "busybox") |
|
| 132 |
+ dir, err := inspectFieldMap(name, "Volumes", "/foo") |
|
| 133 |
+ if err != nil {
|
|
| 134 |
+ t.Fatalf("Error getting volume host path: %q", err)
|
|
| 135 |
+ } |
|
| 136 |
+ |
|
| 137 |
+ if _, err := os.Stat(dir); err != nil && os.IsNotExist(err) {
|
|
| 138 |
+ t.Fatalf("Volume was not created")
|
|
| 139 |
+ } |
|
| 140 |
+ if err != nil {
|
|
| 141 |
+ t.Fatalf("Error statting volume host path: %q", err)
|
|
| 142 |
+ } |
|
| 143 |
+ |
|
| 144 |
+ logDone("create - volumes are created")
|
|
| 145 |
+} |