github.com/gunjan5/docker@v1.8.2/api/client/pull.go (about)

     1  package client
     2  
     3  import (
     4  	"fmt"
     5  	"net/url"
     6  
     7  	Cli "github.com/docker/docker/cli"
     8  	"github.com/docker/docker/graph/tags"
     9  	flag "github.com/docker/docker/pkg/mflag"
    10  	"github.com/docker/docker/pkg/parsers"
    11  	"github.com/docker/docker/registry"
    12  )
    13  
    14  // CmdPull pulls an image or a repository from the registry.
    15  //
    16  // Usage: docker pull [OPTIONS] IMAGENAME[:TAG|@DIGEST]
    17  func (cli *DockerCli) CmdPull(args ...string) error {
    18  	cmd := Cli.Subcmd("pull", []string{"NAME[:TAG|@DIGEST]"}, "Pull an image or a repository from a registry", true)
    19  	allTags := cmd.Bool([]string{"a", "-all-tags"}, false, "Download all tagged images in the repository")
    20  	addTrustedFlags(cmd, true)
    21  	cmd.Require(flag.Exact, 1)
    22  
    23  	cmd.ParseFlags(args, true)
    24  	remote := cmd.Arg(0)
    25  
    26  	taglessRemote, tag := parsers.ParseRepositoryTag(remote)
    27  	if tag == "" && !*allTags {
    28  		tag = tags.DEFAULTTAG
    29  		fmt.Fprintf(cli.out, "Using default tag: %s\n", tag)
    30  	} else if tag != "" && *allTags {
    31  		return fmt.Errorf("tag can't be used with --all-tags/-a")
    32  	}
    33  
    34  	ref := registry.ParseReference(tag)
    35  
    36  	// Resolve the Repository name from fqn to RepositoryInfo
    37  	repoInfo, err := registry.ParseRepositoryInfo(taglessRemote)
    38  	if err != nil {
    39  		return err
    40  	}
    41  
    42  	if isTrusted() && !ref.HasDigest() {
    43  		// Check if tag is digest
    44  		authConfig := registry.ResolveAuthConfig(cli.configFile, repoInfo.Index)
    45  		return cli.trustedPull(repoInfo, ref, authConfig)
    46  	}
    47  
    48  	v := url.Values{}
    49  	v.Set("fromImage", ref.ImageName(taglessRemote))
    50  
    51  	_, _, err = cli.clientRequestAttemptLogin("POST", "/images/create?"+v.Encode(), nil, cli.out, repoInfo.Index, "pull")
    52  	return err
    53  }