| ... | ... |
@@ -168,6 +168,12 @@ func createVolumes(container *Container) error {
|
| 168 | 168 |
return err |
| 169 | 169 |
} |
| 170 | 170 |
} |
| 171 |
+ |
|
| 172 |
+ for volPath := range binds {
|
|
| 173 |
+ if err := initializeVolume(container, volPath, binds); err != nil {
|
|
| 174 |
+ return err |
|
| 175 |
+ } |
|
| 176 |
+ } |
|
| 171 | 177 |
return nil |
| 172 | 178 |
} |
| 173 | 179 |
|
| ... | ... |
@@ -226,7 +232,6 @@ func initializeVolume(container *Container, volPath string, binds map[string]Bin |
| 226 | 226 |
} |
| 227 | 227 |
// Otherwise create an directory in $ROOT/volumes/ and use that |
| 228 | 228 |
} else {
|
| 229 |
- |
|
| 230 | 229 |
// Do not pass a container as the parameter for the volume creation. |
| 231 | 230 |
// The graph driver using the container's information ( Image ) to |
| 232 | 231 |
// create the parent. |
| ... | ... |
@@ -273,38 +278,50 @@ func initializeVolume(container *Container, volPath string, binds map[string]Bin |
| 273 | 273 |
|
| 274 | 274 |
// Do not copy or change permissions if we are mounting from the host |
| 275 | 275 |
if srcRW && !isBindMount {
|
| 276 |
- volList, err := ioutil.ReadDir(rootVolPath) |
|
| 276 |
+ if err := copyExistingContents(rootVolPath, srcPath); err != nil {
|
|
| 277 |
+ return err |
|
| 278 |
+ } |
|
| 279 |
+ } |
|
| 280 |
+ return nil |
|
| 281 |
+} |
|
| 282 |
+ |
|
| 283 |
+func copyExistingContents(rootVolPath, srcPath string) error {
|
|
| 284 |
+ volList, err := ioutil.ReadDir(rootVolPath) |
|
| 285 |
+ if err != nil {
|
|
| 286 |
+ return err |
|
| 287 |
+ } |
|
| 288 |
+ |
|
| 289 |
+ if len(volList) > 0 {
|
|
| 290 |
+ srcList, err := ioutil.ReadDir(srcPath) |
|
| 277 | 291 |
if err != nil {
|
| 278 | 292 |
return err |
| 279 | 293 |
} |
| 280 |
- if len(volList) > 0 {
|
|
| 281 |
- srcList, err := ioutil.ReadDir(srcPath) |
|
| 282 |
- if err != nil {
|
|
| 294 |
+ |
|
| 295 |
+ if len(srcList) == 0 {
|
|
| 296 |
+ // If the source volume is empty copy files from the root into the volume |
|
| 297 |
+ if err := archive.CopyWithTar(rootVolPath, srcPath); err != nil {
|
|
| 283 | 298 |
return err |
| 284 | 299 |
} |
| 285 |
- if len(srcList) == 0 {
|
|
| 286 |
- // If the source volume is empty copy files from the root into the volume |
|
| 287 |
- if err := archive.CopyWithTar(rootVolPath, srcPath); err != nil {
|
|
| 288 |
- return err |
|
| 289 |
- } |
|
| 290 |
- } |
|
| 291 | 300 |
} |
| 301 |
+ } |
|
| 292 | 302 |
|
| 293 |
- var stat syscall.Stat_t |
|
| 294 |
- if err := syscall.Stat(rootVolPath, &stat); err != nil {
|
|
| 295 |
- return err |
|
| 296 |
- } |
|
| 297 |
- var srcStat syscall.Stat_t |
|
| 298 |
- if err := syscall.Stat(srcPath, &srcStat); err != nil {
|
|
| 303 |
+ var ( |
|
| 304 |
+ stat syscall.Stat_t |
|
| 305 |
+ srcStat syscall.Stat_t |
|
| 306 |
+ ) |
|
| 307 |
+ |
|
| 308 |
+ if err := syscall.Stat(rootVolPath, &stat); err != nil {
|
|
| 309 |
+ return err |
|
| 310 |
+ } |
|
| 311 |
+ if err := syscall.Stat(srcPath, &srcStat); err != nil {
|
|
| 312 |
+ return err |
|
| 313 |
+ } |
|
| 314 |
+ // Change the source volume's ownership if it differs from the root |
|
| 315 |
+ // files that were just copied |
|
| 316 |
+ if stat.Uid != srcStat.Uid || stat.Gid != srcStat.Gid {
|
|
| 317 |
+ if err := os.Chown(srcPath, int(stat.Uid), int(stat.Gid)); err != nil {
|
|
| 299 | 318 |
return err |
| 300 | 319 |
} |
| 301 |
- // Change the source volume's ownership if it differs from the root |
|
| 302 |
- // files that were just copied |
|
| 303 |
- if stat.Uid != srcStat.Uid || stat.Gid != srcStat.Gid {
|
|
| 304 |
- if err := os.Chown(srcPath, int(stat.Uid), int(stat.Gid)); err != nil {
|
|
| 305 |
- return err |
|
| 306 |
- } |
|
| 307 |
- } |
|
| 308 | 320 |
} |
| 309 | 321 |
return nil |
| 310 | 322 |
} |
| ... | ... |
@@ -135,8 +135,8 @@ func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Conf |
| 135 | 135 |
if arr[0] == "/" {
|
| 136 | 136 |
return nil, nil, cmd, fmt.Errorf("Invalid bind mount: source can't be '/'")
|
| 137 | 137 |
} |
| 138 |
- dstDir := arr[1] |
|
| 139 |
- flVolumes.Set(dstDir) |
|
| 138 |
+ // after creating the bind mount we want to delete it from the flVolumes values because |
|
| 139 |
+ // we do not want bind mounts being committed to image configs |
|
| 140 | 140 |
binds = append(binds, bind) |
| 141 | 141 |
flVolumes.Delete(bind) |
| 142 | 142 |
} else if bind == "/" {
|