当前位置: 首页>>代码示例>>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;未经允许,请勿转载。