DockerCLI/cli/command
Sebastiaan van Stijn 9e620e990f
implement docker push -a/--all-tags
The `docker push` command up until [v0.9.1](https://github.com/moby/moby/blob/v0.9.1/api/client.go#L998)
always pushed all tags of a given image, so `docker push foo/bar` would push (e.g.)
all of  `foo/bar:latest`, `foo:/bar:v1`, `foo/bar:v1.0.0`.

Pushing all tags of an image was not desirable in many case, so docker v0.10.0
enhanced `docker push` to optionally specify a tag to push (`docker push foo/bar:v1`)
(see https://github.com/moby/moby/issues/3411 and the pull request that implemented
this: https://github.com/moby/moby/pull/4948).

This behavior exists up until today, and is confusing, because unlike other commands,
`docker push` does not default to use the `:latest` tag when omitted, but instead
makes it push "all tags of the image"

For example, in the following situation;

```
docker images

REPOSITORY          TAG                        IMAGE ID            CREATED             SIZE
thajeztah/myimage   latest                     b534869c81f0        41 hours ago        1.22MB
```

Running `docker push thajeztah/myimage` seemingly does the expected behavior (it
pushes `thajeztah/myimage:latest` to Docker Hub), however, it does not so for the
reason expected (`:latest` being the default tag), but because `:latest` happens
to be the only tag present for the `thajeztah/myimage` image.

If another tag exists for the image:

```
docker images

REPOSITORY          TAG                        IMAGE ID            CREATED             SIZE
thajeztah/myimage   latest                     b534869c81f0        41 hours ago        1.22MB
thajeztah/myimage   v1.0.0                     b534869c81f0        41 hours ago        1.22MB
```

Running the same command (`docker push thajeztah/myimage`) will push _both_ images
to Docker Hub.

> Note that the behavior described above is currently not (clearly) documented;
> the `docker push` reference documentation (https://docs.docker.com/engine/reference/commandline/push/)
does not mention that omitting the tag will push all tags

This patch changes the default behavior, and if no tag is specified, `:latest` is
assumed. To push _all_ tags, a new flag (`-a` / `--all-tags`) is added, similar
to the flag that's present on `docker pull`.

With this change:

- `docker push myname/myimage` will be the equivalent of `docker push myname/myimage:latest`
- to push all images, the user needs to set a flag (`--all-tags`), so `docker push --all-tags myname/myimage:latest`

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-01-28 16:21:06 +01:00
..
builder unused-for is a deprecated synonym 2019-10-30 14:52:14 +11:00
checkpoint formatter package heavy refactoring 2018-10-23 17:05:44 +02:00
commands Remove "docker engine" subcommands 2019-12-12 17:51:25 +01:00
config File is not `goimports`-ed (goimports) 2019-10-31 19:22:24 +01:00
container Update flag description for docker rm -v 2020-01-25 13:54:23 +01:00
context cli/command/context: Using the variable on range scope `c` in function literal (scopelint) 2019-10-31 19:22:35 +01:00
formatter Fix docker ps table headers with custom format and "split" or "join" 2019-12-27 12:36:02 +01:00
idresolver File is not `goimports`-ed (goimports) 2019-10-31 19:22:24 +01:00
image implement docker push -a/--all-tags 2020-01-28 16:21:06 +01:00
inspect Update tests to use gotest.tools 👼 2018-06-08 18:24:26 +02:00
manifest Add riscv64 to manifest annotation and bash completion 2019-09-10 13:00:23 -03:00
network Update flag doc 2019-10-29 12:01:30 +01:00
node File is not `goimports`-ed (goimports) 2019-10-31 19:22:24 +01:00
plugin cli/command/plugin/list_test.go:61:31: `TestList$1` - `filter` is unused (unparam) 2019-10-31 19:22:19 +01:00
registry cli/command/registry/login_test.go:66:25: unnecessary conversion (unconvert) 2019-10-31 19:22:25 +01:00
secret cli/command/secret: G101: Potential hardcoded credentials (gosec) 2019-10-31 19:22:27 +01:00
service Add log-driver and options to service inspect "pretty" format 2020-01-17 15:10:36 +01:00
stack Remove experimental "deploy" from "dab" files 2019-12-09 10:34:14 +01:00
swarm File is not `goimports`-ed (goimports) 2019-10-31 19:22:24 +01:00
system cli/command/system/info.go:116:68: prettyPrintClientInfo - result 0 (error) is always nil (unparam) 2019-10-31 19:22:20 +01:00
task File is not `goimports`-ed (goimports) 2019-10-31 19:22:24 +01:00
testdata Dynamically register kubernetes context store endpoint type. 2019-05-20 13:28:11 +01:00
trust implement docker push -a/--all-tags 2020-01-28 16:21:06 +01:00
volume File is not `goimports`-ed (goimports) 2019-10-31 19:22:24 +01:00
cli.go Remove "docker engine" subcommands 2019-12-12 17:51:25 +01:00
cli_options.go Remove "docker engine" subcommands 2019-12-12 17:51:25 +01:00
cli_options_test.go Unit test for WithContentTrustFromEnv 2019-01-29 11:26:40 +00:00
cli_test.go Remove "docker engine" subcommands 2019-12-12 17:51:25 +01:00
context.go Cleanup context store interfaces 2019-04-18 15:49:36 +02:00
defaultcontextstore.go Push check for kubernetes requirement down into the endpoint 2019-05-20 13:28:11 +01:00
defaultcontextstore_test.go cli/command: fix formatting of comments, and minor linting issues 2020-01-16 12:47:12 +01:00
events_utils.go updated vendoring 2017-09-01 19:41:06 -04:00
orchestrator.go Fast Context Switch: commands 2019-01-10 22:25:43 +01:00
orchestrator_test.go Introduce docker context store 2019-01-04 17:06:51 +01:00
registry.go Simplify ElectAuthServer 2019-03-28 21:08:13 +00:00
registry_test.go Remove docker api dependency from cli/config 2019-01-31 21:25:43 +00:00
streams.go Extract streams helpers from command package to their own package to remove a cyclic dependency from command to internal/containerizedengine 2019-01-28 14:36:00 +01:00
trust.go Refactor content_trust cli/flags handling 2018-03-08 15:00:43 -05:00
utils.go docker cp: prevent NPE when failing to stat destination 2019-12-09 15:32:02 +01:00
utils_test.go cp: allow trailing slash in non-existant destination 2019-11-12 17:25:25 +00:00