2015-03-24 23:57:23 -04:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2015-11-18 17:20:54 -05:00
|
|
|
"errors"
|
2015-03-24 23:57:23 -04:00
|
|
|
|
2015-05-05 00:18:28 -04:00
|
|
|
Cli "github.com/docker/docker/cli"
|
2015-03-24 23:57:23 -04:00
|
|
|
flag "github.com/docker/docker/pkg/mflag"
|
2015-12-04 16:55:15 -05:00
|
|
|
"github.com/docker/docker/reference"
|
2016-01-04 19:05:26 -05:00
|
|
|
"github.com/docker/engine-api/types"
|
2015-03-24 23:57:23 -04:00
|
|
|
)
|
|
|
|
|
2015-03-25 13:34:41 -04:00
|
|
|
// CmdTag tags an image into a repository.
|
|
|
|
//
|
|
|
|
// Usage: docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]
|
2015-03-24 23:57:23 -04:00
|
|
|
func (cli *DockerCli) CmdTag(args ...string) error {
|
2015-10-08 08:46:21 -04:00
|
|
|
cmd := Cli.Subcmd("tag", []string{"IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]"}, Cli.DockerCommands["tag"].Description, true)
|
2015-12-01 17:02:02 -05:00
|
|
|
force := cmd.Bool([]string{"#f", "#-force"}, false, "Force the tagging even if there's a conflict")
|
2015-03-24 23:57:23 -04:00
|
|
|
cmd.Require(flag.Exact, 2)
|
|
|
|
|
2015-03-28 21:22:46 -04:00
|
|
|
cmd.ParseFlags(args, true)
|
2015-03-24 23:57:23 -04:00
|
|
|
|
2015-11-18 17:20:54 -05:00
|
|
|
ref, err := reference.ParseNamed(cmd.Arg(1))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-12-04 16:55:15 -05:00
|
|
|
if _, isCanonical := ref.(reference.Canonical); isCanonical {
|
2015-11-18 17:20:54 -05:00
|
|
|
return errors.New("refusing to create a tag with a digest reference")
|
|
|
|
}
|
|
|
|
|
2015-12-10 14:01:34 -05:00
|
|
|
var tag string
|
|
|
|
if tagged, isTagged := ref.(reference.NamedTagged); isTagged {
|
2015-11-18 17:20:54 -05:00
|
|
|
tag = tagged.Tag()
|
|
|
|
}
|
2015-03-24 23:57:23 -04:00
|
|
|
|
2015-12-04 17:02:06 -05:00
|
|
|
options := types.ImageTagOptions{
|
2015-12-04 13:45:51 -05:00
|
|
|
ImageID: cmd.Arg(0),
|
|
|
|
RepositoryName: ref.Name(),
|
|
|
|
Tag: tag,
|
|
|
|
Force: *force,
|
2015-03-24 23:57:23 -04:00
|
|
|
}
|
|
|
|
|
2015-12-04 13:45:51 -05:00
|
|
|
return cli.client.ImageTag(options)
|
2015-03-24 23:57:23 -04:00
|
|
|
}
|