diff --git a/components/engine/commands.go b/components/engine/commands.go index 4be282bce2..cb7b57ff00 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -10,6 +10,7 @@ import ( "log" "net/http" "net/url" + "path/filepath" "runtime" "strconv" "strings" @@ -913,6 +914,25 @@ func (opts AttachOpts) Get(val string) bool { return false } +// PathOpts stores a unique set of absolute paths +type PathOpts map[string]struct{} + +func NewPathOpts() PathOpts { + return make(PathOpts) +} + +func (opts PathOpts) String() string { + return fmt.Sprintf("%v", map[string]struct{}(opts)) +} + +func (opts PathOpts) Set(val string) error { + if !filepath.IsAbs(val) { + return fmt.Errorf("%s is not an absolute path", val) + } + opts[filepath.Clean(val)] = struct{}{} + return nil +} + func (srv *Server) CmdTag(stdin io.ReadCloser, stdout io.Writer, args ...string) error { cmd := rcli.Subcmd(stdout, "tag", "[OPTIONS] IMAGE REPOSITORY [TAG]", "Tag an image into a repository") force := cmd.Bool("f", false, "Force") diff --git a/components/engine/container.go b/components/engine/container.go index bac0951da4..109c8b158b 100644 --- a/components/engine/container.go +++ b/components/engine/container.go @@ -66,6 +66,7 @@ type Config struct { Cmd []string Dns []string Image string // Name of the image as it was passed by the operator (eg. could be symbolic) + Volumes map[string]struct{} } func ParseRun(args []string, stdout io.Writer, capabilities *Capabilities) (*Config, error) { @@ -97,6 +98,9 @@ func ParseRun(args []string, stdout io.Writer, capabilities *Capabilities) (*Con var flDns ListOpts cmd.Var(&flDns, "dns", "Set custom dns servers") + flVolumes := NewPathOpts() + cmd.Var(flVolumes, "v", "Attach a data volume") + if err := cmd.Parse(args); err != nil { return nil, err } @@ -136,6 +140,7 @@ func ParseRun(args []string, stdout io.Writer, capabilities *Capabilities) (*Con Cmd: runCmd, Dns: flDns, Image: image, + Volumes: flVolumes, } if *flMemory > 0 && !capabilities.SwapLimit { diff --git a/components/engine/runtime.go b/components/engine/runtime.go index 6e03226b36..16c98117fd 100644 --- a/components/engine/runtime.go +++ b/components/engine/runtime.go @@ -32,6 +32,7 @@ type Runtime struct { capabilities *Capabilities kernelVersion *KernelVersionInfo autoRestart bool + volumes *Graph } var sysInitPath string @@ -405,6 +406,10 @@ func NewRuntimeFromDirectory(root string, autoRestart bool) (*Runtime, error) { if err != nil { return nil, err } + volumes, err := NewGraph(path.Join(root, "volumes")) + if err != nil { + return nil, err + } repositories, err := NewTagStore(path.Join(root, "repositories"), g) if err != nil { return nil, fmt.Errorf("Couldn't create Tag store: %s", err) @@ -432,6 +437,7 @@ func NewRuntimeFromDirectory(root string, autoRestart bool) (*Runtime, error) { idIndex: NewTruncIndex(), capabilities: &Capabilities{}, autoRestart: autoRestart, + volumes: volumes, } if err := runtime.restore(); err != nil {