2015-03-24 23:57:23 -04:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/url"
|
|
|
|
|
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"
|
|
|
|
"github.com/docker/docker/pkg/parsers"
|
|
|
|
"github.com/docker/docker/registry"
|
|
|
|
)
|
|
|
|
|
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-03-24 23:57:23 -04:00
|
|
|
force := cmd.Bool([]string{"f", "#force", "-force"}, false, "Force")
|
|
|
|
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
|
|
|
|
|
|
|
var (
|
|
|
|
repository, tag = parsers.ParseRepositoryTag(cmd.Arg(1))
|
|
|
|
v = url.Values{}
|
|
|
|
)
|
|
|
|
|
|
|
|
//Check if the given image name can be resolved
|
|
|
|
if err := registry.ValidateRepositoryName(repository); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
v.Set("repo", repository)
|
|
|
|
v.Set("tag", tag)
|
|
|
|
|
|
|
|
if *force {
|
|
|
|
v.Set("force", "1")
|
|
|
|
}
|
|
|
|
|
2015-01-12 14:56:01 -05:00
|
|
|
if _, _, err := readBody(cli.call("POST", "/images/"+cmd.Arg(0)+"/tag?"+v.Encode(), nil, nil)); err != nil {
|
2015-03-24 23:57:23 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|