github.com/chenchun/docker@v1.3.2-0.20150629222414-20467faf132b/api/client/push.go (about) 1 package client 2 3 import ( 4 "fmt" 5 "net/url" 6 7 flag "github.com/docker/docker/pkg/mflag" 8 "github.com/docker/docker/pkg/parsers" 9 "github.com/docker/docker/registry" 10 ) 11 12 // CmdPush pushes an image or repository to the registry. 13 // 14 // Usage: docker push NAME[:TAG] 15 func (cli *DockerCli) CmdPush(args ...string) error { 16 cmd := cli.Subcmd("push", []string{"NAME[:TAG]"}, "Push an image or a repository to the registry", true) 17 cmd.Require(flag.Exact, 1) 18 19 cmd.ParseFlags(args, true) 20 21 name := cmd.Arg(0) 22 23 remote, tag := parsers.ParseRepositoryTag(name) 24 25 // Resolve the Repository name from fqn to RepositoryInfo 26 repoInfo, err := registry.ParseRepositoryInfo(remote) 27 if err != nil { 28 return err 29 } 30 // Resolve the Auth config relevant for this server 31 authConfig := registry.ResolveAuthConfig(cli.configFile, repoInfo.Index) 32 // If we're not using a custom registry, we know the restrictions 33 // applied to repository names and can warn the user in advance. 34 // Custom repositories can have different rules, and we must also 35 // allow pushing by image ID. 36 if repoInfo.Official { 37 username := authConfig.Username 38 if username == "" { 39 username = "<user>" 40 } 41 return fmt.Errorf("You cannot push a \"root\" repository. Please rename your repository to <user>/<repo> (ex: %s/%s)", username, repoInfo.LocalName) 42 } 43 44 v := url.Values{} 45 v.Set("tag", tag) 46 47 _, _, err = cli.clientRequestAttemptLogin("POST", "/images/"+remote+"/push?"+v.Encode(), nil, cli.out, repoInfo.Index, "push") 48 return err 49 }