From 5dcedd536fd0a45b47b443bf1dfe4cf2b569bd6e Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Fri, 17 May 2013 13:23:12 +0000 Subject: [PATCH 01/15] add login check before pull user's repo Upstream-commit: 1b0b962b43afe2f0e07b31fe03e64db4e7d97854 Component: engine --- components/engine/commands.go | 71 +++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 28 deletions(-) diff --git a/components/engine/commands.go b/components/engine/commands.go index 8734da176f..db073f7d44 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -591,39 +591,13 @@ func (cli *DockerCli) CmdPush(args ...string) error { return nil } - body, _, err := cli.call("GET", "/auth", nil) + username, err := cli.checkIfLogged(*registry == "", "push", args...) if err != nil { return err } - var out auth.AuthConfig - err = json.Unmarshal(body, &out) - if err != nil { - return err - } - - // If the login failed AND we're using the index, abort - if *registry == "" && out.Username == "" { - if err := cli.CmdLogin(args...); err != nil { - return err - } - - body, _, err = cli.call("GET", "/auth", nil) - if err != nil { - return err - } - err = json.Unmarshal(body, &out) - if err != nil { - return err - } - - if out.Username == "" { - return fmt.Errorf("Please login prior to push. ('docker login')") - } - } - if len(strings.SplitN(name, "/", 2)) == 1 { - return fmt.Errorf("Impossible to push a \"root\" repository. Please rename your repository in / (ex: %s/%s)", out.Username, name) + return fmt.Errorf("Impossible to push a \"root\" repository. Please rename your repository in / (ex: %s/%s)", username, name) } v := url.Values{} @@ -654,6 +628,13 @@ func (cli *DockerCli) CmdPull(args ...string) error { remote = remoteParts[0] } + if strings.Contains(remote, "/") { + fmt.Println("Login is required before pull an user's repository") + if _, err := cli.checkIfLogged(true, "pull", args...); err != nil { + return err + } + } + v := url.Values{} v.Set("fromImage", remote) v.Set("tag", *tag) @@ -1141,6 +1122,40 @@ func (cli *DockerCli) CmdRun(args ...string) error { return nil } +func (cli *DockerCli) checkIfLogged(condition bool, action string, args ...string) (string, error) { + body, _, err := cli.call("GET", "/auth", nil) + if err != nil { + return "", err + } + + var out auth.AuthConfig + err = json.Unmarshal(body, &out) + if err != nil { + return "", err + } + + // If the login failed + if condition && out.Username == "" { + if err := cli.CmdLogin(args...); err != nil { + return "", err + } + + body, _, err = cli.call("GET", "/auth", nil) + if err != nil { + return "", err + } + err = json.Unmarshal(body, &out) + if err != nil { + return "", err + } + + if out.Username == "" { + return "", fmt.Errorf("Please login prior to %s. ('docker login')", action) + } + } + return out.Username, nil +} + func (cli *DockerCli) call(method, path string, data interface{}) ([]byte, int, error) { var params io.Reader if data != nil { From 726c3246c29f718c6490781ca08da7f3691ff241 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Tue, 21 May 2013 10:14:58 +0000 Subject: [PATCH 02/15] add -host and -port Upstream-commit: a3ccec197e847a996e725d87177067dba98bcca6 Component: engine --- components/engine/commands.go | 4 ++-- components/engine/docker/docker.go | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/components/engine/commands.go b/components/engine/commands.go index 5e459a1d94..0d7dc0e8a1 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -30,8 +30,8 @@ var ( GIT_COMMIT string ) -func ParseCommands(args ...string) error { - cli := NewDockerCli("0.0.0.0", 4243) +func ParseCommands(host string, port int, args ...string) error { + cli := NewDockerCli(host, port) if len(args) > 0 { methodName := "Cmd" + strings.ToUpper(args[0][:1]) + strings.ToLower(args[0][1:]) diff --git a/components/engine/docker/docker.go b/components/engine/docker/docker.go index c8c1a65603..800c8f09c0 100644 --- a/components/engine/docker/docker.go +++ b/components/engine/docker/docker.go @@ -29,6 +29,8 @@ func main() { flAutoRestart := flag.Bool("r", false, "Restart previously running containers") bridgeName := flag.String("b", "", "Attach containers to a pre-existing network bridge") pidfile := flag.String("p", "/var/run/docker.pid", "File containing process PID") + port := flag.Int("port", 4243, "Port to listen/connect to") + host := flag.String("host", "0.0.0.0", "Host bind/connect to") flag.Parse() if *bridgeName != "" { docker.NetworkBridgeIface = *bridgeName @@ -44,12 +46,12 @@ func main() { flag.Usage() return } - if err := daemon(*pidfile, *flAutoRestart); err != nil { + if err := daemon(*pidfile, *host, *port, *flAutoRestart); err != nil { log.Fatal(err) os.Exit(-1) } } else { - if err := docker.ParseCommands(flag.Args()...); err != nil { + if err := docker.ParseCommands(*host, *port, flag.Args()...); err != nil { log.Fatal(err) os.Exit(-1) } @@ -83,7 +85,7 @@ func removePidFile(pidfile string) { } } -func daemon(pidfile string, autoRestart bool) error { +func daemon(pidfile, host string, port int, autoRestart bool) error { if err := createPidFile(pidfile); err != nil { log.Fatal(err) } @@ -103,5 +105,5 @@ func daemon(pidfile string, autoRestart bool) error { return err } - return docker.ListenAndServe("0.0.0.0:4243", server, true) + return docker.ListenAndServe(fmt.Sprintf("%s:%d", host, port), server, true) } From c981be44f5e855d67824b6168dce9a89ea41934b Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 22 May 2013 16:15:52 +0000 Subject: [PATCH 03/15] improved doc and usage Upstream-commit: 800b401f0ba706f8f09b5beacd335caf4548e63c Component: engine --- components/engine/commands.go | 2 +- components/engine/docs/sources/commandline/cli.rst | 4 +++- components/engine/docs/sources/use/basics.rst | 13 +++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/components/engine/commands.go b/components/engine/commands.go index 0d7dc0e8a1..50f8533a27 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -53,7 +53,7 @@ func ParseCommands(host string, port int, args ...string) error { } func (cli *DockerCli) CmdHelp(args ...string) error { - help := "Usage: docker COMMAND [arg...]\n\nA self-sufficient runtime for linux containers.\n\nCommands:\n" + help := "Usage: docker [OPTIONS] COMMAND [arg...]\n -host=\"0.0.0.0\": Host to bind/connect to\n -port=4243: Port to listen/connect to\n\nA self-sufficient runtime for linux containers.\n\nCommands:\n" for cmd, description := range map[string]string{ "attach": "Attach to a running container", "build": "Build a container from Dockerfile or via stdin", diff --git a/components/engine/docs/sources/commandline/cli.rst b/components/engine/docs/sources/commandline/cli.rst index 1a341d3e5d..8ea3d19354 100644 --- a/components/engine/docs/sources/commandline/cli.rst +++ b/components/engine/docs/sources/commandline/cli.rst @@ -14,7 +14,9 @@ To list available commands, either run ``docker`` with no parameters or execute ``docker help``:: $ docker - Usage: docker COMMAND [arg...] + Usage: docker [OPTIONS] COMMAND [arg...] + -host="0.0.0.0": Host to bind/connect to + -port=4243: Port to listen/connect to A self-sufficient runtime for linux containers. diff --git a/components/engine/docs/sources/use/basics.rst b/components/engine/docs/sources/use/basics.rst index ffd2a7b96c..9a5f8faf41 100644 --- a/components/engine/docs/sources/use/basics.rst +++ b/components/engine/docs/sources/use/basics.rst @@ -33,6 +33,19 @@ Running an interactive shell # allocate a tty, attach stdin and stdout docker run -i -t base /bin/bash +Bind Docker to another host/port +-------------------------------- + +If you want Docker to listen to another port and bind to another ip +use -host and -port on both deamon and client + +.. code-block:: bash + + # Run docker in daemon mode + sudo /docker -host 127.0.0.1 -port 5555 & + # Download a base image + docker -port 5555 pull base + Starting a long-running worker process -------------------------------------- From 95bff3248e1ffb59dadadb34b79f943d816893c7 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 23 May 2013 16:09:28 +0000 Subject: [PATCH 04/15] switch to default 127.0.0.1, and mixed the two flags in one. -h Upstream-commit: 13f1939a6316079c14bac5434ecc2c955af1d1fb Component: engine --- components/engine/commands.go | 18 ++++++------- components/engine/docker/docker.go | 27 ++++++++++++++----- .../engine/docs/sources/commandline/cli.rst | 3 +-- components/engine/docs/sources/use/basics.rst | 4 +-- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/components/engine/commands.go b/components/engine/commands.go index 50f8533a27..fda90489e4 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -30,8 +30,8 @@ var ( GIT_COMMIT string ) -func ParseCommands(host string, port int, args ...string) error { - cli := NewDockerCli(host, port) +func ParseCommands(addr string, port int, args ...string) error { + cli := NewDockerCli(addr, port) if len(args) > 0 { methodName := "Cmd" + strings.ToUpper(args[0][:1]) + strings.ToLower(args[0][1:]) @@ -53,7 +53,7 @@ func ParseCommands(host string, port int, args ...string) error { } func (cli *DockerCli) CmdHelp(args ...string) error { - help := "Usage: docker [OPTIONS] COMMAND [arg...]\n -host=\"0.0.0.0\": Host to bind/connect to\n -port=4243: Port to listen/connect to\n\nA self-sufficient runtime for linux containers.\n\nCommands:\n" + help := fmt.Sprintf("Usage: docker [OPTIONS] COMMAND [arg...]\n -h=\"%s:%d\": Host:port to bind/connect to\n\nA self-sufficient runtime for linux containers.\n\nCommands:\n", cli.addr, cli.port) for cmd, description := range map[string]string{ "attach": "Attach to a running container", "build": "Build a container from Dockerfile or via stdin", @@ -1167,7 +1167,7 @@ func (cli *DockerCli) call(method, path string, data interface{}) ([]byte, int, params = bytes.NewBuffer(buf) } - req, err := http.NewRequest(method, fmt.Sprintf("http://%s:%d", cli.host, cli.port)+path, params) + req, err := http.NewRequest(method, fmt.Sprintf("http://%s:%d", cli.addr, cli.port)+path, params) if err != nil { return nil, -1, err } @@ -1199,7 +1199,7 @@ func (cli *DockerCli) stream(method, path string, in io.Reader, out io.Writer) e if (method == "POST" || method == "PUT") && in == nil { in = bytes.NewReader([]byte{}) } - req, err := http.NewRequest(method, fmt.Sprintf("http://%s:%d%s", cli.host, cli.port, path), in) + req, err := http.NewRequest(method, fmt.Sprintf("http://%s:%d%s", cli.addr, cli.port, path), in) if err != nil { return err } @@ -1235,7 +1235,7 @@ func (cli *DockerCli) hijack(method, path string, setRawTerminal bool) error { return err } req.Header.Set("Content-Type", "plain/text") - dial, err := net.Dial("tcp", fmt.Sprintf("%s:%d", cli.host, cli.port)) + dial, err := net.Dial("tcp", fmt.Sprintf("%s:%d", cli.addr, cli.port)) if err != nil { return err } @@ -1289,11 +1289,11 @@ func Subcmd(name, signature, description string) *flag.FlagSet { return flags } -func NewDockerCli(host string, port int) *DockerCli { - return &DockerCli{host, port} +func NewDockerCli(addr string, port int) *DockerCli { + return &DockerCli{addr, port} } type DockerCli struct { - host string + addr string port int } diff --git a/components/engine/docker/docker.go b/components/engine/docker/docker.go index 800c8f09c0..37a0578d51 100644 --- a/components/engine/docker/docker.go +++ b/components/engine/docker/docker.go @@ -10,6 +10,7 @@ import ( "os" "os/signal" "strconv" + "strings" "syscall" ) @@ -23,20 +24,34 @@ func main() { docker.SysInit() return } + host:= "127.0.0.1" + port:= 4243 // FIXME: Switch d and D ? (to be more sshd like) flDaemon := flag.Bool("d", false, "Daemon mode") flDebug := flag.Bool("D", false, "Debug mode") flAutoRestart := flag.Bool("r", false, "Restart previously running containers") bridgeName := flag.String("b", "", "Attach containers to a pre-existing network bridge") pidfile := flag.String("p", "/var/run/docker.pid", "File containing process PID") - port := flag.Int("port", 4243, "Port to listen/connect to") - host := flag.String("host", "0.0.0.0", "Host bind/connect to") + flHost := flag.String("h", fmt.Sprintf("%s:%d", host, port), "Host:port to bind/connect to") flag.Parse() if *bridgeName != "" { docker.NetworkBridgeIface = *bridgeName } else { docker.NetworkBridgeIface = docker.DefaultNetworkBridge } + + if strings.Contains(*flHost, ":") && len(strings.Split(*flHost, ":")) == 2 { + hostParts := strings.Split(*flHost, ":") + if hostParts[0] != "" { + host = hostParts[0] + } + if p, err := strconv.Atoi(hostParts[1]); err == nil { + port = p + } + } else if !strings.Contains(*flHost, ":") { + host = *flHost + } + if *flDebug { os.Setenv("DEBUG", "1") } @@ -46,12 +61,12 @@ func main() { flag.Usage() return } - if err := daemon(*pidfile, *host, *port, *flAutoRestart); err != nil { + if err := daemon(*pidfile, host, port, *flAutoRestart); err != nil { log.Fatal(err) os.Exit(-1) } } else { - if err := docker.ParseCommands(*host, *port, flag.Args()...); err != nil { + if err := docker.ParseCommands(host, port, flag.Args()...); err != nil { log.Fatal(err) os.Exit(-1) } @@ -85,7 +100,7 @@ func removePidFile(pidfile string) { } } -func daemon(pidfile, host string, port int, autoRestart bool) error { +func daemon(pidfile, addr string, port int, autoRestart bool) error { if err := createPidFile(pidfile); err != nil { log.Fatal(err) } @@ -105,5 +120,5 @@ func daemon(pidfile, host string, port int, autoRestart bool) error { return err } - return docker.ListenAndServe(fmt.Sprintf("%s:%d", host, port), server, true) + return docker.ListenAndServe(fmt.Sprintf("%s:%d", addr, port), server, true) } diff --git a/components/engine/docs/sources/commandline/cli.rst b/components/engine/docs/sources/commandline/cli.rst index 8ea3d19354..3bb904b46a 100644 --- a/components/engine/docs/sources/commandline/cli.rst +++ b/components/engine/docs/sources/commandline/cli.rst @@ -15,8 +15,7 @@ To list available commands, either run ``docker`` with no parameters or execute $ docker Usage: docker [OPTIONS] COMMAND [arg...] - -host="0.0.0.0": Host to bind/connect to - -port=4243: Port to listen/connect to + -h="127.0.0.1:4243": Host:port to bind/connect to A self-sufficient runtime for linux containers. diff --git a/components/engine/docs/sources/use/basics.rst b/components/engine/docs/sources/use/basics.rst index 9a5f8faf41..c71147e3f2 100644 --- a/components/engine/docs/sources/use/basics.rst +++ b/components/engine/docs/sources/use/basics.rst @@ -42,9 +42,9 @@ use -host and -port on both deamon and client .. code-block:: bash # Run docker in daemon mode - sudo /docker -host 127.0.0.1 -port 5555 & + sudo /docker -h 0.0.0.0:5555 & # Download a base image - docker -port 5555 pull base + docker -h :5555 pull base Starting a long-running worker process From c30cd2c29a886b2cae0e61465fb7276b4ae3e5e2 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 23 May 2013 16:15:36 +0000 Subject: [PATCH 05/15] added warning Upstream-commit: 59835135c572db08798dde7a5e211e7f4b453742 Component: engine --- components/engine/docker/docker.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/engine/docker/docker.go b/components/engine/docker/docker.go index 37a0578d51..f2dca2de14 100644 --- a/components/engine/docker/docker.go +++ b/components/engine/docker/docker.go @@ -101,6 +101,9 @@ func removePidFile(pidfile string) { } func daemon(pidfile, addr string, port int, autoRestart bool) error { + if addr != "127.0.0.1" { + log.Println("/!\\ DON'T BIND ON ANOTHER IP ADDRESS THAN 127.0.0.1 IF YOU DON'T KNOW WHAT YOU'RE DOING /!\\") + } if err := createPidFile(pidfile); err != nil { log.Fatal(err) } From 386eeafd7a068965bb5f449cf849ef815424a553 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 23 May 2013 16:32:39 +0000 Subject: [PATCH 06/15] bring Error: Command not found: Usage: docker COMMAND [arg...] A self-sufficient runtime for linux containers. Commands: attach Attach to a running container insert Insert a file in an image login Register or Login to the docker registry server export Stream the contents of a container as a tar archive diff Inspect changes on a container's filesystem logs Fetch the logs of a container pull Pull an image or a repository from the docker registry server restart Restart a running container build Build a container from Dockerfile or via stdin history Show the history of an image kill Kill a running container rmi Remove an image start Start a stopped container tag Tag an image into a repository commit Create a new image from a container's changes import Create a new filesystem image from the contents of a tarball ps List containers rm Remove a container run Run a command in a new container wait Block until a container stops, then print its exit code images List images port Lookup the public-facing port which is NAT-ed to PRIVATE_PORT info Display system-wide information inspect Return low-level information on a container push Push an image or a repository to the docker registry server search Search for an image in the docker index stop Stop a running container version Show the docker version information back Upstream-commit: 31c98bdaafd806d7c5e44f2ed25cf57e7ef20827 Component: engine --- components/engine/commands.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/components/engine/commands.go b/components/engine/commands.go index 5e459a1d94..16dfdbfc2b 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -30,15 +30,19 @@ var ( GIT_COMMIT string ) +func (cli *DockerCli) getMethod(name string) (reflect.Method, bool) { + methodName := "Cmd" + strings.ToUpper(name[:1]) + strings.ToLower(name[1:]) + return reflect.TypeOf(cli).MethodByName(methodName) +} + func ParseCommands(args ...string) error { cli := NewDockerCli("0.0.0.0", 4243) if len(args) > 0 { - methodName := "Cmd" + strings.ToUpper(args[0][:1]) + strings.ToLower(args[0][1:]) - method, exists := reflect.TypeOf(cli).MethodByName(methodName) + method, exists := cli.getMethod(args[0]) if !exists { fmt.Println("Error: Command not found:", args[0]) - return cli.CmdHelp(args...) + return cli.CmdHelp(args[1:]...) } ret := method.Func.CallSlice([]reflect.Value{ reflect.ValueOf(cli), @@ -53,6 +57,18 @@ func ParseCommands(args ...string) error { } func (cli *DockerCli) CmdHelp(args ...string) error { + if len(args) > 0 { + method, exists := cli.getMethod(args[0]) + if !exists { + fmt.Println("Error: Command not found:", args[0]) + } else { + method.Func.CallSlice([]reflect.Value{ + reflect.ValueOf(cli), + reflect.ValueOf([]string{"--help"}), + })[0].Interface() + return nil + } + } help := "Usage: docker COMMAND [arg...]\n\nA self-sufficient runtime for linux containers.\n\nCommands:\n" for cmd, description := range map[string]string{ "attach": "Attach to a running container", From 0faea4838c50dfd8ca915d8dedde71b048a0e1a1 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Fri, 24 May 2013 12:23:28 +0000 Subject: [PATCH 07/15] change %f to %g Upstream-commit: a7d7a0665573b3db46963e4eb083f24470aad082 Component: engine --- components/engine/commands.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/engine/commands.go b/components/engine/commands.go index 6212459b42..8112af021f 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -1199,7 +1199,7 @@ func (cli *DockerCli) stream(method, path string, in io.Reader, out io.Writer) e if (method == "POST" || method == "PUT") && in == nil { in = bytes.NewReader([]byte{}) } - req, err := http.NewRequest(method, fmt.Sprintf("http://%s:%d/v%f%s", cli.addr, cli.port, API_VERSION, path), in) + req, err := http.NewRequest(method, fmt.Sprintf("http://%s:%d/v%g%s", cli.addr, cli.port, API_VERSION, path), in) if err != nil { return err } @@ -1230,7 +1230,7 @@ func (cli *DockerCli) stream(method, path string, in io.Reader, out io.Writer) e } func (cli *DockerCli) hijack(method, path string, setRawTerminal bool) error { - req, err := http.NewRequest(method, fmt.Sprintf("/v%f%s", API_VERSION, path), nil) + req, err := http.NewRequest(method, fmt.Sprintf("/v%g%s", API_VERSION, path), nil) if err != nil { return err } From 4631590cee8cd88e3102ad20d1f46990f6d18447 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Fri, 24 May 2013 12:43:24 +0000 Subject: [PATCH 08/15] removed useless params Upstream-commit: 4dab2fccd39858c0fb3b783a612fb95173d34f7b Component: engine --- components/engine/commands.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/components/engine/commands.go b/components/engine/commands.go index db073f7d44..a85a127453 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -591,7 +591,7 @@ func (cli *DockerCli) CmdPush(args ...string) error { return nil } - username, err := cli.checkIfLogged(*registry == "", "push", args...) + username, err := cli.checkIfLogged(*registry == "", "push") if err != nil { return err } @@ -629,8 +629,7 @@ func (cli *DockerCli) CmdPull(args ...string) error { } if strings.Contains(remote, "/") { - fmt.Println("Login is required before pull an user's repository") - if _, err := cli.checkIfLogged(true, "pull", args...); err != nil { + if _, err := cli.checkIfLogged(true, "pull"); err != nil { return err } } @@ -1122,7 +1121,7 @@ func (cli *DockerCli) CmdRun(args ...string) error { return nil } -func (cli *DockerCli) checkIfLogged(condition bool, action string, args ...string) (string, error) { +func (cli *DockerCli) checkIfLogged(condition bool, action string) (string, error) { body, _, err := cli.call("GET", "/auth", nil) if err != nil { return "", err @@ -1134,9 +1133,9 @@ func (cli *DockerCli) checkIfLogged(condition bool, action string, args ...strin return "", err } - // If the login failed + // If condition AND the login failed if condition && out.Username == "" { - if err := cli.CmdLogin(args...); err != nil { + if err := cli.CmdLogin(""); err != nil { return "", err } From bad97e351a6fa5144a4eaf9ceaa227552ca0f289 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Fri, 24 May 2013 14:23:43 +0000 Subject: [PATCH 09/15] fix docker login when same username Upstream-commit: 1f23b4caae6cd60a2bc1911c17fcebcadc539497 Component: engine --- components/engine/api.go | 8 ++++---- components/engine/commands.go | 4 ++-- components/engine/registry/registry.go | 7 ++++++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/components/engine/api.go b/components/engine/api.go index 0a902c4043..216ae027ee 100644 --- a/components/engine/api.go +++ b/components/engine/api.go @@ -59,7 +59,7 @@ func getBoolParam(value string) (bool, error) { } func getAuth(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - b, err := json.Marshal(srv.registry.GetAuthConfig()) + b, err := json.Marshal(srv.registry.GetAuthConfig(false)) if err != nil { return err } @@ -72,9 +72,9 @@ func postAuth(srv *Server, version float64, w http.ResponseWriter, r *http.Reque if err := json.NewDecoder(r.Body).Decode(config); err != nil { return err } - - if config.Username == srv.registry.GetAuthConfig().Username { - config.Password = srv.registry.GetAuthConfig().Password + authConfig := srv.registry.GetAuthConfig(true) + if config.Username == authConfig.Username { + config.Password = authConfig.Password } newAuthConfig := auth.NewAuthConfig(config.Username, config.Password, config.Email, srv.runtime.root) diff --git a/components/engine/commands.go b/components/engine/commands.go index 75ba562cd8..8c4630b828 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -1294,6 +1294,6 @@ func NewDockerCli(host string, port int) *DockerCli { } type DockerCli struct { - host string - port int + host string + port int } diff --git a/components/engine/registry/registry.go b/components/engine/registry/registry.go index ce9b4b4ac7..bd361b5e74 100644 --- a/components/engine/registry/registry.go +++ b/components/engine/registry/registry.go @@ -428,9 +428,14 @@ func (r *Registry) ResetClient(authConfig *auth.AuthConfig) { r.client.Jar = cookiejar.NewCookieJar() } -func (r *Registry) GetAuthConfig() *auth.AuthConfig { +func (r *Registry) GetAuthConfig(withPasswd bool) *auth.AuthConfig { + password := "" + if withPasswd { + password = r.authConfig.Password + } return &auth.AuthConfig{ Username: r.authConfig.Username, + Password: password, Email: r.authConfig.Email, } } From 2b0dd49ab182dd0cfd0f83eeb650d4568cf2e7e6 Mon Sep 17 00:00:00 2001 From: kim0 Date: Fri, 24 May 2013 17:44:02 +0200 Subject: [PATCH 10/15] Avoid hardcoding kernel 3.8 version, allow Ubuntu updates to work Upstream-commit: 8dc2ad2c06fabb6501f0adff80761898bed5bc6f Component: engine --- components/engine/docs/sources/installation/ubuntulinux.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/engine/docs/sources/installation/ubuntulinux.rst b/components/engine/docs/sources/installation/ubuntulinux.rst index 6d2d3e671d..0aaa76250e 100644 --- a/components/engine/docs/sources/installation/ubuntulinux.rst +++ b/components/engine/docs/sources/installation/ubuntulinux.rst @@ -38,7 +38,7 @@ Due to a bug in LXC docker works best on the 3.8 kernel. Precise comes with a 3. .. code-block:: bash # install the backported kernel - sudo apt-get update && sudo apt-get install linux-image-3.8.0-19-generic + sudo apt-get update && sudo apt-get install linux-image-generic-lts-raring # reboot sudo reboot From 1cfe074da1fcbfd1e13320fedcb4d82c3ca8c84b Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Fri, 24 May 2013 16:49:18 +0000 Subject: [PATCH 11/15] use -H Upstream-commit: 92e4a51965ce862ad1b4682a68b33550f2fd613f Component: engine --- components/engine/commands.go | 2 +- components/engine/docker/docker.go | 2 +- components/engine/docs/sources/commandline/cli.rst | 2 +- components/engine/docs/sources/use/basics.rst | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/components/engine/commands.go b/components/engine/commands.go index 8112af021f..5333ec40c3 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -53,7 +53,7 @@ func ParseCommands(addr string, port int, args ...string) error { } func (cli *DockerCli) CmdHelp(args ...string) error { - help := fmt.Sprintf("Usage: docker [OPTIONS] COMMAND [arg...]\n -h=\"%s:%d\": Host:port to bind/connect to\n\nA self-sufficient runtime for linux containers.\n\nCommands:\n", cli.addr, cli.port) + help := fmt.Sprintf("Usage: docker [OPTIONS] COMMAND [arg...]\n -H=\"%s:%d\": Host:port to bind/connect to\n\nA self-sufficient runtime for linux containers.\n\nCommands:\n", cli.addr, cli.port) for cmd, description := range map[string]string{ "attach": "Attach to a running container", "build": "Build a container from Dockerfile or via stdin", diff --git a/components/engine/docker/docker.go b/components/engine/docker/docker.go index f2dca2de14..28b4d7f927 100644 --- a/components/engine/docker/docker.go +++ b/components/engine/docker/docker.go @@ -32,7 +32,7 @@ func main() { flAutoRestart := flag.Bool("r", false, "Restart previously running containers") bridgeName := flag.String("b", "", "Attach containers to a pre-existing network bridge") pidfile := flag.String("p", "/var/run/docker.pid", "File containing process PID") - flHost := flag.String("h", fmt.Sprintf("%s:%d", host, port), "Host:port to bind/connect to") + flHost := flag.String("H", fmt.Sprintf("%s:%d", host, port), "Host:port to bind/connect to") flag.Parse() if *bridgeName != "" { docker.NetworkBridgeIface = *bridgeName diff --git a/components/engine/docs/sources/commandline/cli.rst b/components/engine/docs/sources/commandline/cli.rst index 3bb904b46a..02691b4f56 100644 --- a/components/engine/docs/sources/commandline/cli.rst +++ b/components/engine/docs/sources/commandline/cli.rst @@ -15,7 +15,7 @@ To list available commands, either run ``docker`` with no parameters or execute $ docker Usage: docker [OPTIONS] COMMAND [arg...] - -h="127.0.0.1:4243": Host:port to bind/connect to + -H="127.0.0.1:4243": Host:port to bind/connect to A self-sufficient runtime for linux containers. diff --git a/components/engine/docs/sources/use/basics.rst b/components/engine/docs/sources/use/basics.rst index 4c450fbc97..378028703c 100644 --- a/components/engine/docs/sources/use/basics.rst +++ b/components/engine/docs/sources/use/basics.rst @@ -42,9 +42,9 @@ use -host and -port on both deamon and client .. code-block:: bash # Run docker in daemon mode - sudo /docker -h 0.0.0.0:5555 & + sudo /docker -H 0.0.0.0:5555 & # Download a base image - docker -h :5555 pull base + docker -H :5555 pull base Starting a long-running worker process From 0575fdb313384f2f12cdd9527f872898aaecf2bc Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Fri, 24 May 2013 11:31:11 -0700 Subject: [PATCH 12/15] Fix issue within auth test Upstream-commit: 0146f65a448d2d42271300f1477ea9fa378d6360 Component: engine --- components/engine/api_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/engine/api_test.go b/components/engine/api_test.go index de4289728e..06413e1303 100644 --- a/components/engine/api_test.go +++ b/components/engine/api_test.go @@ -56,7 +56,7 @@ func TestGetAuth(t *testing.T) { t.Fatalf("%d OK or 0 expected, received %d\n", http.StatusOK, r.Code) } - newAuthConfig := srv.registry.GetAuthConfig() + newAuthConfig := srv.registry.GetAuthConfig(false) if newAuthConfig.Username != authConfig.Username || newAuthConfig.Email != authConfig.Email { t.Fatalf("The auth configuration hasn't been set correctly") From 68053e95b66d9b102b943c375772364817204382 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Fri, 24 May 2013 11:31:19 -0700 Subject: [PATCH 13/15] Gofmt Upstream-commit: ae72c2f4d6c37a14fcd81658f6ae42d65f5c7169 Component: engine --- components/engine/docker/docker.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/engine/docker/docker.go b/components/engine/docker/docker.go index 28b4d7f927..1749b2fd39 100644 --- a/components/engine/docker/docker.go +++ b/components/engine/docker/docker.go @@ -24,8 +24,8 @@ func main() { docker.SysInit() return } - host:= "127.0.0.1" - port:= 4243 + host := "127.0.0.1" + port := 4243 // FIXME: Switch d and D ? (to be more sshd like) flDaemon := flag.Bool("d", false, "Daemon mode") flDebug := flag.Bool("D", false, "Debug mode") From e668458c4bc4e2509561e867a78fc04e0eb0c2aa Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Fri, 24 May 2013 11:31:36 -0700 Subject: [PATCH 14/15] Simplify the Host flag parsing Upstream-commit: bfb65b733a2cfa0dac6a5760897f09d8e2557381 Component: engine --- components/engine/docker/docker.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/components/engine/docker/docker.go b/components/engine/docker/docker.go index 1749b2fd39..7b8aa7f858 100644 --- a/components/engine/docker/docker.go +++ b/components/engine/docker/docker.go @@ -40,15 +40,19 @@ func main() { docker.NetworkBridgeIface = docker.DefaultNetworkBridge } - if strings.Contains(*flHost, ":") && len(strings.Split(*flHost, ":")) == 2 { + if strings.Contains(*flHost, ":") { hostParts := strings.Split(*flHost, ":") + if len(hostParts) != 2 { + log.Fatal("Invalid bind address format.") + os.Exit(-1) + } if hostParts[0] != "" { host = hostParts[0] } if p, err := strconv.Atoi(hostParts[1]); err == nil { port = p } - } else if !strings.Contains(*flHost, ":") { + } else { host = *flHost } From d66839e06f23d0ff5fcb178112b127a74f3457ee Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Fri, 24 May 2013 11:56:21 -0700 Subject: [PATCH 15/15] Fix merge issue Upstream-commit: a3293ed854675074d7f5d5c2bca63ba9fa599deb Component: engine --- components/engine/api.go | 1 - components/engine/commands.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/components/engine/api.go b/components/engine/api.go index 216ae027ee..a99828e961 100644 --- a/components/engine/api.go +++ b/components/engine/api.go @@ -662,6 +662,5 @@ func ListenAndServe(addr string, srv *Server, logging bool) error { r.Path(localRoute).Methods(localMethod).HandlerFunc(f) } } - return http.ListenAndServe(addr, r) } diff --git a/components/engine/commands.go b/components/engine/commands.go index 1c83e30454..8622225138 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -36,7 +36,7 @@ func (cli *DockerCli) getMethod(name string) (reflect.Method, bool) { } func ParseCommands(addr string, port int, args ...string) error { - cli := NewDockerCli("0.0.0.0", 4243) + cli := NewDockerCli(addr, port) if len(args) > 0 { method, exists := cli.getMethod(args[0])