當前位置: 首頁>>代碼示例>>Golang>>正文


Golang utils.ReplaceOrAppendEnvValues函數代碼示例

本文整理匯總了Golang中github.com/dotcloud/docker/utils.ReplaceOrAppendEnvValues函數的典型用法代碼示例。如果您正苦於以下問題:Golang ReplaceOrAppendEnvValues函數的具體用法?Golang ReplaceOrAppendEnvValues怎麽用?Golang ReplaceOrAppendEnvValues使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了ReplaceOrAppendEnvValues函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: createRuntimeEnvironment

func (container *Container) createRuntimeEnvironment(linkedEnv []string) []string {
	// Setup environment
	env := []string{
		"HOME=/",
		"PATH=" + DefaultPathEnv,
		"HOSTNAME=" + container.Config.Hostname,
	}
	if container.Config.Tty {
		env = append(env, "TERM=xterm")
	}
	env = append(env, linkedEnv...)
	// because the env on the container can override certain default values
	// we need to replace the 'env' keys where they match and append anything
	// else.
	env = utils.ReplaceOrAppendEnvValues(env, container.Config.Env)

	return env
}
開發者ID:hughdbrown,項目名稱:docker,代碼行數:18,代碼來源:container.go

示例2: Start


//.........這裏部分代碼省略.........
		for linkAlias, child := range children {
			if !child.State.IsRunning() {
				return fmt.Errorf("Cannot link to a non running container: %s AS %s", child.Name, linkAlias)
			}

			link, err := links.NewLink(
				container.NetworkSettings.IPAddress,
				child.NetworkSettings.IPAddress,
				linkAlias,
				child.Config.Env,
				child.Config.ExposedPorts,
				runtime.eng)

			if err != nil {
				rollback()
				return err
			}

			container.activeLinks[link.Alias()] = link
			if err := link.Enable(); err != nil {
				rollback()
				return err
			}

			for _, envVar := range link.ToEnv() {
				env = append(env, envVar)
			}
		}
	}

	// because the env on the container can override certain default values
	// we need to replace the 'env' keys where they match and append anything
	// else.
	env = utils.ReplaceOrAppendEnvValues(env, container.Config.Env)
	if err := container.generateEnvConfig(env); err != nil {
		return err
	}

	if container.Config.WorkingDir != "" {
		container.Config.WorkingDir = path.Clean(container.Config.WorkingDir)

		pthInfo, err := os.Stat(path.Join(container.basefs, container.Config.WorkingDir))
		if err != nil {
			if !os.IsNotExist(err) {
				return err
			}
			if err := os.MkdirAll(path.Join(container.basefs, container.Config.WorkingDir), 0755); err != nil {
				return err
			}
		}
		if pthInfo != nil && !pthInfo.IsDir() {
			return fmt.Errorf("Cannot mkdir: %s is not a directory", container.Config.WorkingDir)
		}
	}

	envPath, err := container.EnvConfigPath()
	if err != nil {
		return err
	}

	populateCommand(container)
	container.command.Env = env

	if err := setupMountsForContainer(container, envPath); err != nil {
		return err
	}
開發者ID:jpgbus,項目名稱:docker,代碼行數:67,代碼來源:container.go


注:本文中的github.com/dotcloud/docker/utils.ReplaceOrAppendEnvValues函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。