当前位置: 首页>>代码示例>>Golang>>正文


Golang client.NewDockerClient函数代码示例

本文整理汇总了Golang中github.com/ailispaw/talk2docker/client.NewDockerClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewDockerClient函数的具体用法?Golang NewDockerClient怎么用?Golang NewDockerClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewDockerClient函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: pullImageInSilence

func pullImageInSilence(ctx *cobra.Command, name string) error {
	r, n, t, err := client.ParseRepositoryName(name)
	if err != nil {
		return err
	}
	name = n + ":" + t
	if r != "" {
		name = r + "/" + name
	}

	f, err := os.Open(os.DevNull)
	if err != nil {
		return err
	}

	docker, err := client.NewDockerClient(configPath, hostName, f)
	if err != nil {
		return err
	}

	if _, err := docker.PullImage(name); err != nil {
		return err
	}

	return nil
}
开发者ID:ChengTiesheng,项目名称:talk2docker,代码行数:26,代码来源:image.go

示例2: inspectContainers

func inspectContainers(ctx *cobra.Command, args []string) {
	if len(args) < 1 {
		ErrorExit(ctx, "Needs an argument <NAME|ID> at least to inspect")
	}

	docker, err := client.NewDockerClient(configPath, hostName, ctx.Out())
	if err != nil {
		log.Fatal(err)
	}

	var containers []api.ContainerInfo
	var gotError = false

	for _, name := range args {
		if containerInfo, err := docker.InspectContainer(name); err != nil {
			log.Error(err)
			gotError = true
		} else {
			containers = append(containers, *containerInfo)
		}
	}

	if len(containers) > 0 {
		if err := FormatPrint(ctx.Out(), containers); err != nil {
			log.Fatal(err)
		}
	}

	if gotError {
		log.Fatal("Error: failed to inspect one or more containers")
	}
}
开发者ID:ChengTiesheng,项目名称:talk2docker,代码行数:32,代码来源:container.go

示例3: getContainerChanges

func getContainerChanges(ctx *cobra.Command, args []string) {
	if len(args) < 1 {
		ErrorExit(ctx, "Needs an argument <NAME|ID> to get changes")
	}

	docker, err := client.NewDockerClient(configPath, hostName, ctx.Out())
	if err != nil {
		log.Fatal(err)
	}

	changes, err := docker.GetContainerChanges(args[0])
	if err != nil {
		log.Fatal(err)
	}

	for _, change := range changes {
		var kind string
		switch change.Kind {
		case api.CHANGE_TYPE_MODIFY:
			kind = "C"
		case api.CHANGE_TYPE_ADD:
			kind = "A"
		case api.CHANGE_TYPE_DELETE:
			kind = "D"
		}
		ctx.Printf("%s %s\n", kind, change.Path)
	}
}
开发者ID:ChengTiesheng,项目名称:talk2docker,代码行数:28,代码来源:container.go

示例4: inspectImages

func inspectImages(ctx *cobra.Command, args []string) {
	if len(args) < 1 {
		ErrorExit(ctx, "Needs an argument <NAME[:TAG]|ID> at least to inspect")
	}

	docker, err := client.NewDockerClient(configPath, hostName, ctx.Out())
	if err != nil {
		log.Fatal(err)
	}

	var images []api.ImageInfo
	var gotError = false

	for _, name := range args {
		if imageInfo, err := docker.InspectImage(name); err != nil {
			log.Error(err)
			gotError = true
		} else {
			images = append(images, *imageInfo)
		}
	}

	if len(images) > 0 {
		if err := FormatPrint(ctx.Out(), images); err != nil {
			log.Fatal(err)
		}
	}

	if gotError {
		log.Fatal("Error: failed to inspect one or more images")
	}
}
开发者ID:ChengTiesheng,项目名称:talk2docker,代码行数:32,代码来源:image.go

示例5: getContainerProcesses

func getContainerProcesses(ctx *cobra.Command, args []string) {
	if len(args) < 1 {
		ErrorExit(ctx, "Needs an argument <NAME|ID> to execute ps")
	}

	docker, err := client.NewDockerClient(configPath, hostName, ctx.Out())
	if err != nil {
		log.Fatal(err)
	}

	ps_args := ""
	if len(args) > 1 {
		ps_args = strings.Join(args[1:], " ")
	}

	ps, err := docker.GetContainerProcesses(args[0], ps_args)
	if err != nil {
		log.Fatal(err)
	}

	if boolYAML || boolJSON {
		if err := FormatPrint(ctx.Out(), ps); err != nil {
			log.Fatal(err)
		}
		return
	}

	PrintInTable(ctx.Out(), ps.Titles, ps.Processes, 100, tablewriter.ALIGN_DEFAULT)
}
开发者ID:ChengTiesheng,项目名称:talk2docker,代码行数:29,代码来源:container.go

示例6: commitContainer

func commitContainer(ctx *cobra.Command, args []string) {
	if len(args) < 2 {
		ErrorExit(ctx, "Needs two arguments to commit <CONTAINER-NAME|ID> to <IMAGE-NAME[:TAG]>")
	}

	reg, name, tag, err := client.ParseRepositoryName(args[1])
	if err != nil {
		log.Fatal(err)
	}

	if reg != "" {
		name = reg + "/" + name
	}

	docker, err := client.NewDockerClient(configPath, hostName, ctx.Out())
	if err != nil {
		log.Fatal(err)
	}

	if _, err := docker.CommitContainer(args[0], name, tag, message, author, boolPause); err != nil {
		log.Fatal(err)
	}

	ctx.Printf("Committed %s as %s:%s\n", args[0], name, tag)
}
开发者ID:ChengTiesheng,项目名称:talk2docker,代码行数:25,代码来源:container.go

示例7: tagImage

func tagImage(ctx *cobra.Command, args []string) {
	if len(args) < 2 {
		ErrorExit(ctx, "Needs two arguments <NAME[:TAG]|ID> <NEW-NAME[:TAG]>")
	}

	reg, name, tag, err := client.ParseRepositoryName(args[1])
	if err != nil {
		log.Fatal(err)
	}

	if reg != "" {
		name = reg + "/" + name
	}

	docker, err := client.NewDockerClient(configPath, hostName, ctx.Out())
	if err != nil {
		log.Fatal(err)
	}

	if err := docker.TagImage(args[0], name, tag, boolForce); err != nil {
		log.Fatal(err)
	}

	ctx.Printf("Tagged %s as %s:%s\n", args[0], name, tag)
}
开发者ID:ChengTiesheng,项目名称:talk2docker,代码行数:25,代码来源:image.go

示例8: pullImage

func pullImage(ctx *cobra.Command, args []string) {
	if len(args) < 1 {
		ErrorExit(ctx, "Needs an argument <NAME[:TAG]> to pull")
	}

	reg, name, tag, err := client.ParseRepositoryName(args[0])
	if err != nil {
		log.Fatal(err)
	}

	repository := name + ":" + tag

	if boolAll {
		repository = name
	}

	if reg != "" {
		repository = reg + "/" + repository
	}

	docker, err := client.NewDockerClient(configPath, hostName, ctx.Out())
	if err != nil {
		log.Fatal(err)
	}

	if _, err := docker.PullImage(repository); err != nil {
		log.Fatal(err)
	}
}
开发者ID:ChengTiesheng,项目名称:talk2docker,代码行数:29,代码来源:image.go

示例9: searchImages

func searchImages(ctx *cobra.Command, args []string) {
	if len(args) < 1 {
		ErrorExit(ctx, "Needs an argument <TERM> to search")
	}

	docker, err := client.NewDockerClient(configPath, hostName, ctx.Out())
	if err != nil {
		log.Fatal(err)
	}

	images, err := docker.SearchImages(args[0])
	if err != nil {
		log.Fatal(err)
	}

	if boolStar {
		sort.Sort(sort.Reverse(api.SortImagesByStars{ImageSearchResults: images}))
	} else {
		sort.Sort(api.SortImagesByName{ImageSearchResults: images})
	}

	if boolQuiet {
		for _, image := range images {
			ctx.Println(image.Name)
		}
		return
	}

	if boolYAML || boolJSON {
		if err := FormatPrint(ctx.Out(), images); err != nil {
			log.Fatal(err)
		}
		return
	}

	var items [][]string

	for _, image := range images {
		out := []string{
			image.Name,
			image.Description,
			FormatInt(int64(image.Stars)),
			FormatBool(image.Official, "*", " "),
			FormatBool(image.Automated, "*", " "),
		}
		items = append(items, out)
	}

	header := []string{
		"Name",
		"Description",
		"Stars",
		"Official",
		"Automated",
	}

	PrintInTable(ctx.Out(), header, items, 50, tablewriter.ALIGN_DEFAULT)
}
开发者ID:ChengTiesheng,项目名称:talk2docker,代码行数:58,代码来源:image.go

示例10: exportVolume

func exportVolume(ctx *cobra.Command, args []string) {
	if len(args) < 1 {
		ErrorExit(ctx, "Needs an argument <ID|CONTAINER-NAME:PATH> to export")
	}

	volumes, err := getVolumes(ctx)
	if err != nil {
		log.Fatal(err)
	}

	volume := volumes.Find(args[0])
	if volume == nil {
		log.Fatalf("No such volume: %s", args[0])
	}

	var (
		config     api.Config
		hostConfig api.HostConfig
	)

	config.Image = "busybox:latest"

	hostConfig.Binds = []string{volume.Path + ":/" + volume.ID}

	docker, err := client.NewDockerClient(configPath, hostName, ctx.Out())
	if err != nil {
		log.Fatal(err)
	}

	var cid string
	cid, err = docker.CreateContainer("", config, hostConfig)
	if err != nil {
		if apiErr, ok := err.(api.Error); ok && (apiErr.StatusCode == 404) {
			if err := pullImageInSilence(ctx, config.Image); err != nil {
				log.Fatal(err)
			}

			cid, err = docker.CreateContainer("", config, hostConfig)
			if err != nil {
				log.Fatal(err)
			}
		} else {
			log.Fatal(err)
		}
	}
	defer docker.RemoveContainer(cid, true)

	if err := docker.CopyContainer(cid, "/"+volume.ID); err != nil {
		log.Fatal(err)
	}
}
开发者ID:ChengTiesheng,项目名称:talk2docker,代码行数:51,代码来源:volume.go

示例11: removeVolume

func removeVolume(ctx *cobra.Command, volume *Volume) error {
	var (
		config     api.Config
		hostConfig api.HostConfig
	)

	config.Cmd = []string{"/bin/sh", "-c", "rm -rf /.docker_volume_config/" + volume.ID}
	config.Image = "busybox:latest"

	hostConfig.Binds = []string{filepath.Dir(volume.configPath) + ":/.docker_volume_config"}

	if !volume.IsBindMount {
		config.Cmd[2] = config.Cmd[2] + (" && rm -rf /.docker_volume/" + volume.ID)

		hostConfig.Binds = append(hostConfig.Binds, filepath.Dir(volume.Path)+":/.docker_volume")
	}

	docker, err := client.NewDockerClient(configPath, hostName, ctx.Out())
	if err != nil {
		return err
	}

	var cid string
	cid, err = docker.CreateContainer("", config, hostConfig)
	if err != nil {
		if apiErr, ok := err.(api.Error); ok && (apiErr.StatusCode == 404) {
			if err := pullImageInSilence(ctx, config.Image); err != nil {
				return err
			}

			cid, err = docker.CreateContainer("", config, hostConfig)
			if err != nil {
				return err
			}
		} else {
			return err
		}
	}
	defer docker.RemoveContainer(cid, true)

	if err := docker.StartContainer(cid); err != nil {
		return err
	}

	if _, err := docker.WaitContainer(cid); err != nil {
		return err
	}

	return nil
}
开发者ID:ChengTiesheng,项目名称:talk2docker,代码行数:50,代码来源:volume.go

示例12: buildImage

func buildImage(ctx *cobra.Command, args []string) {
	path := "."
	if len(args) > 0 {
		path = args[0]
	}

	docker, err := client.NewDockerClient(configPath, hostName, ctx.Out())
	if err != nil {
		log.Fatal(err)
	}

	if _, err := docker.BuildImage(path, imageTag, boolQuiet); err != nil {
		log.Fatal(err)
	}
}
开发者ID:ChengTiesheng,项目名称:talk2docker,代码行数:15,代码来源:image.go

示例13: exportContainer

func exportContainer(ctx *cobra.Command, args []string) {
	if len(args) < 1 {
		ErrorExit(ctx, "Needs an argument <NAME|ID> to export")
	}

	docker, err := client.NewDockerClient(configPath, hostName, ctx.Out())
	if err != nil {
		log.Fatal(err)
	}

	if len(args) > 1 {
		if err := docker.CopyContainer(args[0], args[1]); err != nil {
			log.Fatal(err)
		}
	} else {
		if err := docker.ExportContainer(args[0]); err != nil {
			log.Fatal(err)
		}
	}
}
开发者ID:ChengTiesheng,项目名称:talk2docker,代码行数:20,代码来源:container.go

示例14: pushImage

func pushImage(ctx *cobra.Command, args []string) {
	if len(args) < 1 {
		ErrorExit(ctx, "Needs an argument <NAME[:TAG]> to push")
	}

	reg, name, tag, err := client.ParseRepositoryName(args[0])
	if err != nil {
		log.Fatal(err)
	}

	if len(strings.SplitN(name, "/", 2)) == 1 {
		log.Fatalf("You cannot push a \"root\" repository. Please rename your repository in <yourname>/%s", name)
	}

	if reg != "" {
		name = reg + "/" + name
	}

	config, err := client.LoadConfig(configPath)
	if err != nil {
		log.Fatal(err)
	}

	if reg == "" {
		reg = client.INDEX_SERVER
	}

	registry, err := config.GetRegistry(reg)
	if (err != nil) || (registry.Credentials == "") {
		log.Fatal("Please login prior to pushing an image.")
	}

	docker, err := client.NewDockerClient(configPath, hostName, ctx.Out())
	if err != nil {
		log.Fatal(err)
	}

	if _, err := docker.PushImage(name, tag, registry.Credentials); err != nil {
		log.Fatal(err)
	}
}
开发者ID:ChengTiesheng,项目名称:talk2docker,代码行数:41,代码来源:image.go

示例15: removeImages

func removeImages(ctx *cobra.Command, args []string) {
	if len(args) < 1 {
		ErrorExit(ctx, "Needs an argument <NAME[:TAG]> at least to remove")
	}

	docker, err := client.NewDockerClient(configPath, hostName, ctx.Out())
	if err != nil {
		log.Fatal(err)
	}

	var gotError = false
	for _, name := range args {
		if err := docker.RemoveImage(name, boolForce, boolNoPrune); err != nil {
			log.Error(err)
			gotError = true
		}
	}
	if gotError {
		log.Fatal("Error: failed to remove one or more images")
	}
}
开发者ID:ChengTiesheng,项目名称:talk2docker,代码行数:21,代码来源:image.go


注:本文中的github.com/ailispaw/talk2docker/client.NewDockerClient函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。