2015-03-24 23:57:23 -04:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/url"
|
|
|
|
|
2015-05-05 00:18:28 -04:00
|
|
|
Cli "github.com/docker/docker/cli"
|
2015-05-11 13:23:32 -04:00
|
|
|
"github.com/docker/docker/graph/tags"
|
2015-03-24 23:57:23 -04:00
|
|
|
flag "github.com/docker/docker/pkg/mflag"
|
|
|
|
"github.com/docker/docker/pkg/parsers"
|
|
|
|
"github.com/docker/docker/registry"
|
|
|
|
)
|
|
|
|
|
2015-03-25 13:34:41 -04:00
|
|
|
// CmdPull pulls an image or a repository from the registry.
|
|
|
|
//
|
|
|
|
// Usage: docker pull [OPTIONS] IMAGENAME[:TAG|@DIGEST]
|
2015-03-24 23:57:23 -04:00
|
|
|
func (cli *DockerCli) CmdPull(args ...string) error {
|
2015-05-05 00:18:28 -04:00
|
|
|
cmd := Cli.Subcmd("pull", []string{"NAME[:TAG|@DIGEST]"}, "Pull an image or a repository from a registry", true)
|
2015-03-24 23:57:23 -04:00
|
|
|
allTags := cmd.Bool([]string{"a", "-all-tags"}, false, "Download all tagged images in the repository")
|
2015-07-15 16:42:45 -04:00
|
|
|
addTrustedFlags(cmd, true)
|
2015-03-24 23:57:23 -04:00
|
|
|
cmd.Require(flag.Exact, 1)
|
|
|
|
|
2015-03-28 21:22:46 -04:00
|
|
|
cmd.ParseFlags(args, true)
|
2015-07-15 16:42:45 -04:00
|
|
|
remote := cmd.Arg(0)
|
2015-03-24 23:57:23 -04:00
|
|
|
|
|
|
|
taglessRemote, tag := parsers.ParseRepositoryTag(remote)
|
|
|
|
if tag == "" && !*allTags {
|
2015-07-29 19:45:47 -04:00
|
|
|
tag = tags.DefaultTag
|
2015-07-15 16:42:45 -04:00
|
|
|
fmt.Fprintf(cli.out, "Using default tag: %s\n", tag)
|
|
|
|
} else if tag != "" && *allTags {
|
2015-03-24 23:57:23 -04:00
|
|
|
return fmt.Errorf("tag can't be used with --all-tags/-a")
|
|
|
|
}
|
|
|
|
|
2015-07-15 16:42:45 -04:00
|
|
|
ref := registry.ParseReference(tag)
|
2015-03-24 23:57:23 -04:00
|
|
|
|
|
|
|
// Resolve the Repository name from fqn to RepositoryInfo
|
|
|
|
repoInfo, err := registry.ParseRepositoryInfo(taglessRemote)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-07-15 16:42:45 -04:00
|
|
|
if isTrusted() && !ref.HasDigest() {
|
|
|
|
// Check if tag is digest
|
|
|
|
authConfig := registry.ResolveAuthConfig(cli.configFile, repoInfo.Index)
|
|
|
|
return cli.trustedPull(repoInfo, ref, authConfig)
|
|
|
|
}
|
|
|
|
|
|
|
|
v := url.Values{}
|
|
|
|
v.Set("fromImage", ref.ImageName(taglessRemote))
|
|
|
|
|
2015-01-12 14:56:01 -05:00
|
|
|
_, _, err = cli.clientRequestAttemptLogin("POST", "/images/create?"+v.Encode(), nil, cli.out, repoInfo.Index, "pull")
|
|
|
|
return err
|
2015-03-24 23:57:23 -04:00
|
|
|
}
|