Browse code

Merge pull request #9089 from cpuguy83/8942_create_volumes_on_create

Initialize volumes when container is created

Jessie Frazelle authored on 2014/12/04 08:42:09
Showing 3 changed files
... ...
@@ -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
 	}
... ...
@@ -58,6 +58,9 @@ a list of daemon labels (`Labels`).
58 58
 **New!**
59 59
 You can set the new container's MAC address explicitly.
60 60
 
61
+**New!**
62
+Volumes are now initialized when the container is created.
63
+
61 64
 `POST /containers/(id)/start`
62 65
 
63 66
 **New!**
... ...
@@ -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
+}