github.com/hamo/docker@v1.11.1/api/client/tag.go (about) 1 package client 2 3 import ( 4 "errors" 5 6 "golang.org/x/net/context" 7 8 Cli "github.com/docker/docker/cli" 9 flag "github.com/docker/docker/pkg/mflag" 10 "github.com/docker/docker/reference" 11 "github.com/docker/engine-api/types" 12 ) 13 14 // CmdTag tags an image into a repository. 15 // 16 // Usage: docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG] 17 func (cli *DockerCli) CmdTag(args ...string) error { 18 cmd := Cli.Subcmd("tag", []string{"IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]"}, Cli.DockerCommands["tag"].Description, true) 19 force := cmd.Bool([]string{"#f", "#-force"}, false, "Force the tagging even if there's a conflict") 20 cmd.Require(flag.Exact, 2) 21 22 cmd.ParseFlags(args, true) 23 24 ref, err := reference.ParseNamed(cmd.Arg(1)) 25 if err != nil { 26 return err 27 } 28 29 if _, isCanonical := ref.(reference.Canonical); isCanonical { 30 return errors.New("refusing to create a tag with a digest reference") 31 } 32 33 var tag string 34 if tagged, isTagged := ref.(reference.NamedTagged); isTagged { 35 tag = tagged.Tag() 36 } 37 38 options := types.ImageTagOptions{ 39 ImageID: cmd.Arg(0), 40 RepositoryName: ref.Name(), 41 Tag: tag, 42 Force: *force, 43 } 44 45 return cli.client.ImageTag(context.Background(), options) 46 }