From 4099a31304863edf5b4d1b594b41c7ce1a33c5e1 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Wed, 10 Apr 2013 16:23:30 -0700 Subject: [PATCH] Implement the -volumes-from in order to mount volumes from an other container --- container.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/container.go b/container.go index 5de931dc43..7bd5a791ac 100644 --- a/container.go +++ b/container.go @@ -68,6 +68,7 @@ type Config struct { Dns []string Image string // Name of the image as it was passed by the operator (eg. could be symbolic) Volumes map[string]struct{} + VolumesFrom string } func ParseRun(args []string, stdout io.Writer, capabilities *Capabilities) (*Config, error) { @@ -102,6 +103,8 @@ func ParseRun(args []string, stdout io.Writer, capabilities *Capabilities) (*Con flVolumes := NewPathOpts() cmd.Var(flVolumes, "v", "Attach a data volume") + flVolumesFrom := cmd.String("volumes-from", "", "Mount volumes from the specified container") + if err := cmd.Parse(args); err != nil { return nil, err } @@ -142,6 +145,7 @@ func ParseRun(args []string, stdout io.Writer, capabilities *Capabilities) (*Con Dns: flDns, Image: image, Volumes: flVolumes, + VolumesFrom: *flVolumesFrom, } if *flMemory > 0 && !capabilities.SwapLimit { @@ -414,6 +418,22 @@ func (container *Container) Start() error { } } + if container.Config.VolumesFrom != "" { + c := container.runtime.Get(container.Config.VolumesFrom) + if c == nil { + return fmt.Errorf("Container %s not found. Impossible to mount its volumes") + } + for volPath, id := range c.Volumes { + if _, exists := container.Volumes[volPath]; exists { + return fmt.Errorf("The requested volume %s overlap one of the volume of the container %s", volPath, c.Id) + } + if err := os.MkdirAll(path.Join(container.RootfsPath(), volPath), 0755); err != nil { + return nil + } + container.Volumes[volPath] = id + } + } + if err := container.generateLXCConfig(); err != nil { return err }