本文整理汇总了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
}
示例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)
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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)
}
示例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)
}