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


Golang Client.PullImage方法代码示例

本文整理汇总了Golang中github.com/fsouza/go-dockerclient.Client.PullImage方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.PullImage方法的具体用法?Golang Client.PullImage怎么用?Golang Client.PullImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/fsouza/go-dockerclient.Client的用法示例。


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

示例1: pullImage

func pullImage(client *dockerclient.Client, service *Service, image string) error {
	taglessRemote, tag := parsers.ParseRepositoryTag(image)
	if tag == "" {
		image = utils.ImageReference(taglessRemote, DefaultTag)
	}

	repoInfo, err := registry.ParseRepositoryInfo(taglessRemote)
	if err != nil {
		return err
	}

	authConfig := cliconfig.AuthConfig{}
	if service.context.ConfigFile != nil && repoInfo != nil && repoInfo.Index != nil {
		authConfig = registry.ResolveAuthConfig(service.context.ConfigFile, repoInfo.Index)
	}

	err = client.PullImage(
		dockerclient.PullImageOptions{
			Repository:   image,
			OutputStream: os.Stderr, // TODO maybe get the stream from some configured place
		},
		dockerclient.AuthConfiguration{
			Username: authConfig.Username,
			Password: authConfig.Password,
			Email:    authConfig.Email,
		},
	)

	if err != nil {
		logrus.Errorf("Failed to pull image %s: %v", image, err)
	}

	return err
}
开发者ID:schmunk42,项目名称:libcompose,代码行数:34,代码来源:container.go

示例2: pullImage

// pullImage pulls the inspected image using the given client.
// It will try to use all the given authentication methods and will fail
// only if all of them failed.
func (i *defaultImageInspector) pullImage(client *docker.Client) error {
	log.Printf("Pulling image %s", i.opts.Image)

	var imagePullAuths *docker.AuthConfigurations
	var authCfgErr error
	if imagePullAuths, authCfgErr = i.getAuthConfigs(); authCfgErr != nil {
		return authCfgErr
	}

	reader, writer := io.Pipe()
	// handle closing the reader/writer in the method that creates them
	defer writer.Close()
	defer reader.Close()
	imagePullOption := docker.PullImageOptions{
		Repository:    i.opts.Image,
		OutputStream:  writer,
		RawJSONStream: true,
	}

	bytesChan := make(chan int)
	go aggregateBytesAndReport(bytesChan)
	go decodeDockerPullMessages(bytesChan, reader)

	// Try all the possible auth's from the config file
	var authErr error
	for name, auth := range imagePullAuths.Configs {
		if authErr = client.PullImage(imagePullOption, auth); authErr == nil {
			return nil
		}
		log.Printf("Authentication with %s failed: %v", name, authErr)
	}
	return fmt.Errorf("Unable to pull docker image: %v\n", authErr)
}
开发者ID:openshift,项目名称:image-inspector,代码行数:36,代码来源:image-inspector.go

示例3: pullImages

func pullImages(client *dockerapi.Client, images []string) error {
	for _, image := range images {
		err := client.PullImage(dockerapi.PullImageOptions{
			Repository: image,
		}, dockerapi.AuthConfiguration{})
		if err != nil {
			return err
		}
	}

	return nil
}
开发者ID:raceli,项目名称:resolvable,代码行数:12,代码来源:pool.go

示例4: pullImage

func pullImage(data *Data, client *dc.Client, image string) error {
	// TODO: Test local registry handling. It should be working
	// based on the code that was ported over

	pullOpts := parseImageOptions(image)
	auth := dc.AuthConfiguration{}

	if err := client.PullImage(pullOpts, auth); err != nil {
		return fmt.Errorf("Error pulling image %s: %s\n", image, err)
	}

	return fetchLocalImages(data, client)
}
开发者ID:hashicorp,项目名称:terraform,代码行数:13,代码来源:resource_docker_image_funcs.go

示例5: pullImage

// pullImage creates an image by pulling it from a docker registry
func (d *DockerDriver) pullImage(driverConfig *DockerDriverConfig, client *docker.Client, repo string, tag string) error {
	pullOptions := docker.PullImageOptions{
		Repository: repo,
		Tag:        tag,
	}

	authOptions := docker.AuthConfiguration{}
	if len(driverConfig.Auth) != 0 {
		authOptions = docker.AuthConfiguration{
			Username:      driverConfig.Auth[0].Username,
			Password:      driverConfig.Auth[0].Password,
			Email:         driverConfig.Auth[0].Email,
			ServerAddress: driverConfig.Auth[0].ServerAddress,
		}
	}

	if authConfigFile := d.config.Read("docker.auth.config"); authConfigFile != "" {
		if f, err := os.Open(authConfigFile); err == nil {
			defer f.Close()
			var authConfigurations *docker.AuthConfigurations
			if authConfigurations, err = docker.NewAuthConfigurations(f); err != nil {
				return fmt.Errorf("Failed to create docker auth object: %v", err)
			}

			authConfigurationKey := ""
			if driverConfig.SSL {
				authConfigurationKey += "https://"
			}

			authConfigurationKey += strings.Split(driverConfig.ImageName, "/")[0]
			if authConfiguration, ok := authConfigurations.Configs[authConfigurationKey]; ok {
				authOptions = authConfiguration
			} else {
				d.logger.Printf("[INFO] Failed to find docker auth with key %s", authConfigurationKey)
			}
		} else {
			return fmt.Errorf("Failed to open auth config file: %v, error: %v", authConfigFile, err)
		}
	}

	err := client.PullImage(pullOptions, authOptions)
	if err != nil {
		d.logger.Printf("[ERR] driver.docker: failed pulling container %s:%s: %s", repo, tag, err)
		return d.recoverablePullError(err, driverConfig.ImageName)
	}
	d.logger.Printf("[DEBUG] driver.docker: docker pull %s:%s succeeded", repo, tag)
	return nil
}
开发者ID:zanella,项目名称:nomad,代码行数:49,代码来源:docker.go

示例6: PullImage

func PullImage(client *docker.Client, image, username, password, email string) error {
	opts := docker.PullImageOptions{
		Repository: image,
		//OutputStream: os.Stdout,
	}

	auth := docker.AuthConfiguration{
		Username: username,
		Password: password,
		Email:    email,
	}

	if err := client.PullImage(opts, auth); err != nil {
		return err
	}

	return nil
}
开发者ID:ywk253100,项目名称:registry_p2p,代码行数:18,代码来源:docker.go

示例7: pullImage

func pullImage(data *Data, client *dc.Client, image string) error {
	// TODO: Test local registry handling. It should be working
	// based on the code that was ported over

	pullOpts := dc.PullImageOptions{}

	splitImageName := strings.Split(image, ":")
	switch len(splitImageName) {

	// It's in registry:port/username/repo:tag or registry:port/repo:tag format
	case 3:
		splitPortRepo := strings.Split(splitImageName[1], "/")
		pullOpts.Registry = splitImageName[0] + ":" + splitPortRepo[0]
		pullOpts.Tag = splitImageName[2]
		pullOpts.Repository = pullOpts.Registry + "/" + strings.Join(splitPortRepo[1:], "/")

	// It's either registry:port/username/repo, registry:port/repo,
	// or repo:tag with default registry
	case 2:
		splitPortRepo := strings.Split(splitImageName[1], "/")
		switch len(splitPortRepo) {
		// repo:tag
		case 1:
			pullOpts.Repository = splitImageName[0]
			pullOpts.Tag = splitImageName[1]

		// registry:port/username/repo or registry:port/repo
		default:
			pullOpts.Registry = splitImageName[0] + ":" + splitPortRepo[0]
			pullOpts.Repository = pullOpts.Registry + "/" + strings.Join(splitPortRepo[1:], "/")
			pullOpts.Tag = "latest"
		}

	// Plain username/repo or repo
	default:
		pullOpts.Repository = image
	}

	if err := client.PullImage(pullOpts, dc.AuthConfiguration{}); err != nil {
		return fmt.Errorf("Error pulling image %s: %s\n", image, err)
	}

	return fetchLocalImages(data, client)
}
开发者ID:RezaDKhan,项目名称:terraform,代码行数:44,代码来源:resource_docker_image_funcs.go

示例8: pullImage

func pullImage(name string, client *docker.Client) error {
	chunks := strings.Split(name, ":")

	imgName := chunks[0]
	imgTag := "latest"

	if len(chunks) == 2 {
		imgTag = chunks[1]
	}

	auth := docker.AuthConfiguration{}
	opts := docker.PullImageOptions{
		Repository:   imgName,
		Tag:          imgTag,
		OutputStream: os.Stdout,
	}

	return client.PullImage(opts, auth)
}
开发者ID:P0rtk3y,项目名称:api,代码行数:19,代码来源:main.go


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