1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

docker run -v PATH: bind a new data volume to a container

This commit is contained in:
Solomon Hykes 2013-04-05 18:00:10 -07:00 committed by Guillaume J. Charmes
parent 19df5a7965
commit 1df5f4094b
3 changed files with 31 additions and 0 deletions

View file

@ -10,6 +10,7 @@ import (
"log" "log"
"net/http" "net/http"
"net/url" "net/url"
"path/filepath"
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
@ -913,6 +914,25 @@ func (opts AttachOpts) Get(val string) bool {
return false 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 { 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") cmd := rcli.Subcmd(stdout, "tag", "[OPTIONS] IMAGE REPOSITORY [TAG]", "Tag an image into a repository")
force := cmd.Bool("f", false, "Force") force := cmd.Bool("f", false, "Force")

View file

@ -66,6 +66,7 @@ type Config struct {
Cmd []string Cmd []string
Dns []string Dns []string
Image string // Name of the image as it was passed by the operator (eg. could be symbolic) 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) { 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 var flDns ListOpts
cmd.Var(&flDns, "dns", "Set custom dns servers") 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 { if err := cmd.Parse(args); err != nil {
return nil, err return nil, err
} }
@ -136,6 +140,7 @@ func ParseRun(args []string, stdout io.Writer, capabilities *Capabilities) (*Con
Cmd: runCmd, Cmd: runCmd,
Dns: flDns, Dns: flDns,
Image: image, Image: image,
Volumes: flVolumes,
} }
if *flMemory > 0 && !capabilities.SwapLimit { if *flMemory > 0 && !capabilities.SwapLimit {

View file

@ -32,6 +32,7 @@ type Runtime struct {
capabilities *Capabilities capabilities *Capabilities
kernelVersion *KernelVersionInfo kernelVersion *KernelVersionInfo
autoRestart bool autoRestart bool
volumes *Graph
} }
var sysInitPath string var sysInitPath string
@ -405,6 +406,10 @@ func NewRuntimeFromDirectory(root string, autoRestart bool) (*Runtime, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
volumes, err := NewGraph(path.Join(root, "volumes"))
if err != nil {
return nil, err
}
repositories, err := NewTagStore(path.Join(root, "repositories"), g) repositories, err := NewTagStore(path.Join(root, "repositories"), g)
if err != nil { if err != nil {
return nil, fmt.Errorf("Couldn't create Tag store: %s", err) 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(), idIndex: NewTruncIndex(),
capabilities: &Capabilities{}, capabilities: &Capabilities{},
autoRestart: autoRestart, autoRestart: autoRestart,
volumes: volumes,
} }
if err := runtime.restore(); err != nil { if err := runtime.restore(); err != nil {