pull.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package client
  2. import (
  3. "fmt"
  4. "net/url"
  5. "github.com/docker/docker/graph"
  6. flag "github.com/docker/docker/pkg/mflag"
  7. "github.com/docker/docker/pkg/parsers"
  8. "github.com/docker/docker/registry"
  9. "github.com/docker/docker/utils"
  10. )
  11. // CmdPull pulls an image or a repository from the registry.
  12. //
  13. // Usage: docker pull [OPTIONS] IMAGENAME[:TAG|@DIGEST]
  14. func (cli *DockerCli) CmdPull(args ...string) error {
  15. cmd := cli.Subcmd("pull", "NAME[:TAG|@DIGEST]", "Pull an image or a repository from the registry", true)
  16. allTags := cmd.Bool([]string{"a", "-all-tags"}, false, "Download all tagged images in the repository")
  17. cmd.Require(flag.Exact, 1)
  18. cmd.ParseFlags(args, true)
  19. var (
  20. v = url.Values{}
  21. remote = cmd.Arg(0)
  22. newRemote = remote
  23. )
  24. taglessRemote, tag := parsers.ParseRepositoryTag(remote)
  25. if tag == "" && !*allTags {
  26. newRemote = utils.ImageReference(taglessRemote, graph.DEFAULTTAG)
  27. }
  28. if tag != "" && *allTags {
  29. return fmt.Errorf("tag can't be used with --all-tags/-a")
  30. }
  31. v.Set("fromImage", newRemote)
  32. // Resolve the Repository name from fqn to RepositoryInfo
  33. repoInfo, err := registry.ParseRepositoryInfo(taglessRemote)
  34. if err != nil {
  35. return err
  36. }
  37. _, _, err = cli.clientRequestAttemptLogin("POST", "/images/create?"+v.Encode(), nil, cli.out, repoInfo.Index, "pull")
  38. return err
  39. }