2015-03-24 23:57:23 -04:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
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-05-13 22:45:01 -04:00
|
|
|
cmd := cli.Subcmd("tag", []string{"IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]"}, "Tag an image into a repository", 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
|
|
|
|
}
|