Просмотр исходного кода

Merge pull request #7759 from unclejack/pull_latest_by_default

make docker pull only the latest tag by default
Michael Crosby 11 лет назад
Родитель
Сommit
85314e7e58
4 измененных файлов с 26 добавлено и 13 удалено
  1. 13 10
      api/client/commands.go
  2. 3 0
      builder/internals.go
  3. 4 1
      docs/man/docker-pull.1.md
  4. 6 2
      docs/sources/reference/commandline/cli.md

+ 13 - 10
api/client/commands.go

@@ -1192,7 +1192,7 @@ func (cli *DockerCli) CmdPush(args ...string) error {
 
 
 func (cli *DockerCli) CmdPull(args ...string) error {
 func (cli *DockerCli) CmdPull(args ...string) error {
 	cmd := cli.Subcmd("pull", "NAME[:TAG]", "Pull an image or a repository from the registry")
 	cmd := cli.Subcmd("pull", "NAME[:TAG]", "Pull an image or a repository from the registry")
-	tag := cmd.String([]string{"#t", "#-tag"}, "", "Download tagged image in a repository")
+	allTags := cmd.Bool([]string{"a", "-all-tags"}, false, "Download all tagged images in the repository")
 	if err := cmd.Parse(args); err != nil {
 	if err := cmd.Parse(args); err != nil {
 		return nil
 		return nil
 	}
 	}
@@ -1202,19 +1202,22 @@ func (cli *DockerCli) CmdPull(args ...string) error {
 		return nil
 		return nil
 	}
 	}
 	var (
 	var (
-		v      = url.Values{}
-		remote = cmd.Arg(0)
+		v         = url.Values{}
+		remote    = cmd.Arg(0)
+		newRemote = remote
 	)
 	)
-
-	v.Set("fromImage", remote)
-
-	if *tag == "" {
-		v.Set("tag", *tag)
+	taglessRemote, tag := parsers.ParseRepositoryTag(remote)
+	if tag == "" && !*allTags {
+		newRemote = taglessRemote + ":latest"
+	}
+	if tag != "" && *allTags {
+		return fmt.Errorf("tag can't be used with --all-tags/-a")
 	}
 	}
 
 
-	remote, _ = parsers.ParseRepositoryTag(remote)
+	v.Set("fromImage", newRemote)
+
 	// Resolve the Repository name from fqn to hostname + name
 	// Resolve the Repository name from fqn to hostname + name
-	hostname, _, err := registry.ResolveRepositoryName(remote)
+	hostname, _, err := registry.ResolveRepositoryName(taglessRemote)
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}

+ 3 - 0
builder/internals.go

@@ -266,6 +266,9 @@ func (b *Builder) runContextCommand(args []string, allowRemote bool, allowDecomp
 
 
 func (b *Builder) pullImage(name string) (*imagepkg.Image, error) {
 func (b *Builder) pullImage(name string) (*imagepkg.Image, error) {
 	remote, tag := parsers.ParseRepositoryTag(name)
 	remote, tag := parsers.ParseRepositoryTag(name)
+	if tag == "" {
+		tag = "latest"
+	}
 	pullRegistryAuth := b.AuthConfig
 	pullRegistryAuth := b.AuthConfig
 	if len(b.AuthConfigFile.Configs) > 0 {
 	if len(b.AuthConfigFile.Configs) > 0 {
 		// The request came with a full auth config file, we prefer to use that
 		// The request came with a full auth config file, we prefer to use that

+ 4 - 1
docs/man/docker-pull.1.md

@@ -6,6 +6,7 @@ docker-pull - Pull an image or a repository from the registry
 
 
 # SYNOPSIS
 # SYNOPSIS
 **docker pull**
 **docker pull**
+[**-a**|**--all-tags**[=*false*]]
 NAME[:TAG]
 NAME[:TAG]
 
 
 # DESCRIPTION
 # DESCRIPTION
@@ -16,7 +17,8 @@ images for that repository name are pulled down including any tags.
 It is also possible to specify a non-default registry to pull from.
 It is also possible to specify a non-default registry to pull from.
 
 
 # OPTIONS
 # OPTIONS
-There are no available options.
+**-a**, **--all-tags**=*true*|*false*
+   Download all tagged images in the repository. The default is *false*.
 
 
 # EXAMPLES
 # EXAMPLES
 
 
@@ -53,3 +55,4 @@ There are no available options.
 April 2014, Originally compiled by William Henry (whenry at redhat dot com)
 April 2014, Originally compiled by William Henry (whenry at redhat dot com)
 based on docker.com source material and internal work.
 based on docker.com source material and internal work.
 June 2014, updated by Sven Dowideit <SvenDowideit@home.org.au>
 June 2014, updated by Sven Dowideit <SvenDowideit@home.org.au>
+August 2014, updated by Sven Dowideit <SvenDowideit@home.org.au>

+ 6 - 2
docs/sources/reference/commandline/cli.md

@@ -852,6 +852,8 @@ This shows all the containers that have exited with status of '0'
 
 
     Pull an image or a repository from the registry
     Pull an image or a repository from the registry
 
 
+      -a, --all-tags=false    Download all tagged images in the repository
+
 Most of your images will be created on top of a base image from the
 Most of your images will be created on top of a base image from the
 [Docker Hub](https://hub.docker.com) registry.
 [Docker Hub](https://hub.docker.com) registry.
 
 
@@ -867,11 +869,13 @@ To download a particular image, or set of images (i.e., a repository),
 use `docker pull`:
 use `docker pull`:
 
 
     $ docker pull debian
     $ docker pull debian
-    # will pull all the images in the debian repository
+    # will pull only the debian:latest image and its intermediate layers 
     $ docker pull debian:testing
     $ docker pull debian:testing
     # will pull only the image named debian:testing and any intermediate layers
     # will pull only the image named debian:testing and any intermediate layers
-    # it is based on. (Typically the empty `scratch` image, a MAINTAINERs layer,
+    # it is based on. (Typically the empty `scratch` image, a MAINTAINER layer,
     # and the un-tarred base).
     # and the un-tarred base).
+    $ docker pull --all-tags centos
+    # will pull all the images from the centos repository
     $ docker pull registry.hub.docker.com/debian
     $ docker pull registry.hub.docker.com/debian
     # manually specifies the path to the default Docker registry. This could
     # manually specifies the path to the default Docker registry. This could
     # be replaced with the path to a local registry to pull from another source.
     # be replaced with the path to a local registry to pull from another source.