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