瀏覽代碼

Make volumes-from a slice instead of string split
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)

Michael Crosby 11 年之前
父節點
當前提交
b4f2821e6d
共有 3 個文件被更改,包括 8 次插入6 次删除
  1. 4 2
      runconfig/hostconfig.go
  2. 1 1
      runconfig/parse.go
  3. 3 3
      runtime/volumes.go

+ 4 - 2
runconfig/hostconfig.go

@@ -16,7 +16,7 @@ type HostConfig struct {
 	PublishAllPorts bool
 	Dns             []string
 	DnsSearch       []string
-	VolumesFrom     string
+	VolumesFrom     []string
 }
 
 func ContainerHostConfigFromJob(job *engine.Job) *HostConfig {
@@ -24,7 +24,6 @@ func ContainerHostConfigFromJob(job *engine.Job) *HostConfig {
 		ContainerIDFile: job.Getenv("ContainerIDFile"),
 		Privileged:      job.GetenvBool("Privileged"),
 		PublishAllPorts: job.GetenvBool("PublishAllPorts"),
-		VolumesFrom:     job.Getenv("VolumesFrom"),
 	}
 	job.GetenvJson("LxcConf", &hostConfig.LxcConf)
 	job.GetenvJson("PortBindings", &hostConfig.PortBindings)
@@ -40,5 +39,8 @@ func ContainerHostConfigFromJob(job *engine.Job) *HostConfig {
 	if DnsSearch := job.GetenvList("DnsSearch"); DnsSearch != nil {
 		hostConfig.DnsSearch = DnsSearch
 	}
+	if VolumesFrom := job.GetenvList("VolumesFrom"); VolumesFrom != nil {
+		hostConfig.VolumesFrom = VolumesFrom
+	}
 	return hostConfig
 }

+ 1 - 1
runconfig/parse.go

@@ -229,7 +229,7 @@ func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Conf
 		PublishAllPorts: *flPublishAll,
 		Dns:             flDns.GetAll(),
 		DnsSearch:       flDnsSearch.GetAll(),
-		VolumesFrom:     strings.Join(flVolumesFrom.GetAll(), ","),
+		VolumesFrom:     flVolumesFrom.GetAll(),
 	}
 
 	if sysInfo != nil && flMemory > 0 && !sysInfo.SwapLimit {

+ 3 - 3
runtime/volumes.go

@@ -60,8 +60,8 @@ func setupMountsForContainer(container *Container, envPath string) error {
 
 func applyVolumesFrom(container *Container) error {
 	volumesFrom := container.hostConfig.VolumesFrom
-	if volumesFrom != "" {
-		for _, containerSpec := range strings.Split(volumesFrom, ",") {
+	if len(volumesFrom) > 0 {
+		for _, containerSpec := range volumesFrom {
 			var (
 				mountRW   = true
 				specParts = strings.SplitN(containerSpec, ":", 2)
@@ -69,7 +69,7 @@ func applyVolumesFrom(container *Container) error {
 
 			switch len(specParts) {
 			case 0:
-				return fmt.Errorf("Malformed volumes-from specification: %s", volumesFrom)
+				return fmt.Errorf("Malformed volumes-from specification: %s", containerSpec)
 			case 2:
 				switch specParts[1] {
 				case "ro":