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


Golang DockerClient.Exec方法代碼示例

本文整理匯總了Golang中github.com/samalba/dockerclient.DockerClient.Exec方法的典型用法代碼示例。如果您正苦於以下問題:Golang DockerClient.Exec方法的具體用法?Golang DockerClient.Exec怎麽用?Golang DockerClient.Exec使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/samalba/dockerclient.DockerClient的用法示例。


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

示例1: startDocker

func startDocker(docker *dockerclient.DockerClient, s2 string, s3 string, s4 string) {

	var dirpath string = "/tmp/shareDocker" + s3
	os.RemoveAll(dirpath)
	os.Mkdir(dirpath, 0777)
	var filepath string = dirpath + "/config.ini"

	//l4g.Info("startDocker -> %v", filepath)
	var RS string = fmt.Sprintf("startDocker -> %v", filepath)
	l4g.Info(RS)
	writeSDLstr(RS)

	f, _ := os.Create(filepath)
	f.WriteString("ip_broker=rabbitmq\n")
	f.Sync()
	f.WriteString("\n")
	f.Sync()
	f.WriteString(s2)
	f.Sync()
	f.WriteString("\n")
	defer f.Close()

	//l4g.Info("Init the client")
	RS = fmt.Sprintf("Init the client")
	l4g.Info(RS)
	writeSDLstr(RS)
	l4g.Info(os.Getenv("DOCKER_HOST"))

	//l4g.Info("DOCKER_HOST")
	RS = fmt.Sprintf("DOCKER_HOST")
	l4g.Info(RS)
	writeSDLstr(RS)

	var dockerName string = "docker" + s3

	supprDocker(docker, dockerName)

	//l4g.Info(" Create a container")
	RS = fmt.Sprintf(" Create a container")
	l4g.Info(RS)
	writeSDLstr(RS)
	containerConfig := &dockerclient.ContainerConfig{
		Image: "hwgrepo:hwg",
		User:  "developer",
		//		Env: []string{"PATH=\/home\/developer\/sdl_sensor_broker\/"},
		Cmd:          []string{"sh"},
		AttachStdin:  false,
		AttachStdout: false,
		AttachStderr: false,
		Tty:          true,
		OpenStdin:    true,
		StdinOnce:    false,
	}
	containerId, err := docker.CreateContainer(containerConfig, dockerName)

	if err != nil {
		log.Fatal(err)
	}
	var port_tcp string = s3 + "/tcp"
	portBinding := map[string][]dockerclient.PortBinding{port_tcp: {{"", s3}}}

	var sharedDocker string = dirpath + ":/home/developer/sdl_sensor_broker/log"

	l4g.Info(" Start the container")
	hostConfig := &dockerclient.HostConfig{
		Binds:        []string{sharedDocker, "/tmp/.X11-unix:/tmp/.X11-unix:rw"},
		Privileged:   true,
		PortBindings: portBinding,
		Links:        []string{"rabbitmq:rabbitmq"},
	}
	err = docker.StartContainer(containerId, hostConfig)
	if err != nil {
		log.Fatal(err)
	}

	execConfig := &dockerclient.ExecConfig{
		AttachStdin:  false,
		AttachStdout: false,
		AttachStderr: false,
		Tty:          true,
		Cmd:          []string{"sh", "runNoVNCplayer.sh", s4, s3},
		Container:    containerId,
		Detach:       true}

	_, err = docker.Exec(execConfig)

	if err != nil {
		log.Fatal(err)
		l4g.Info(" error exec container")
		RS = fmt.Sprintf(" error exec container")
		l4g.Info(RS)
		writeSDLstr(RS)
	}

}
開發者ID:AlexandreBRUXELLE,項目名稱:goStartDockerViaRabbitMQ,代碼行數:95,代碼來源:main.go


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