From 627f7fdbfdfeb281e73e04623915d515e02cf697 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Mon, 6 May 2013 14:24:14 -0700 Subject: [PATCH 01/95] + Website: new quotes --- docs/sources/index.html | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/docs/sources/index.html b/docs/sources/index.html index 1d5313cf5..ead0a402d 100644 --- a/docs/sources/index.html +++ b/docs/sources/index.html @@ -152,6 +152,35 @@
+ +
+
+
+ + Matt Townsend‏@mtownsend: I have a serious code crush on docker.io - it's Lego for PaaS. Motherfucking awesome Lego. +
+
+
+
+ + Rob Harrop‏@robertharrop: Impressed by @getdocker - it's all kinds of magic. Serious rethink of AWS architecture happening @skillsmatter. +
+
+
+
+
+
+ + Mitchell Hashimoto‏@mitchellh: Docker launched today. It is incredible. They’re also working RIGHT NOW on a Vagrant provider. LXC is COMING!! +
+
+
+
+ + Adam Jacob‏@adamhjk: Docker is clearly the right idea. @solomonstre absolutely killed it. Containerized app deployment is the future, I think. +
+
+
From f796b9c76eb29ae80ea47d290fba3403ab8e1b4c Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Mon, 6 May 2013 14:26:07 -0700 Subject: [PATCH 02/95] * Website: Bigger twitter profile pictures --- docs/sources/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/sources/index.html b/docs/sources/index.html index ead0a402d..1be7e571b 100644 --- a/docs/sources/index.html +++ b/docs/sources/index.html @@ -156,13 +156,13 @@
- + Matt Townsend‏@mtownsend: I have a serious code crush on docker.io - it's Lego for PaaS. Motherfucking awesome Lego.
- + Rob Harrop‏@robertharrop: Impressed by @getdocker - it's all kinds of magic. Serious rethink of AWS architecture happening @skillsmatter.
From b6af9d3d2eb4e1b409f022264192923a631cd85a Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Mon, 6 May 2013 14:26:58 -0700 Subject: [PATCH 03/95] * Website: put Adam's and Mitchell's nice tweets on top :) --- docs/sources/index.html | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/sources/index.html b/docs/sources/index.html index 1be7e571b..8d2ec4a81 100644 --- a/docs/sources/index.html +++ b/docs/sources/index.html @@ -153,20 +153,6 @@
-
-
-
- - Matt Townsend‏@mtownsend: I have a serious code crush on docker.io - it's Lego for PaaS. Motherfucking awesome Lego. -
-
-
-
- - Rob Harrop‏@robertharrop: Impressed by @getdocker - it's all kinds of magic. Serious rethink of AWS architecture happening @skillsmatter. -
-
-
@@ -181,6 +167,20 @@
+
+
+
+ + Matt Townsend‏@mtownsend: I have a serious code crush on docker.io - it's Lego for PaaS. Motherfucking awesome Lego. +
+
+
+
+ + Rob Harrop‏@robertharrop: Impressed by @getdocker - it's all kinds of magic. Serious rethink of AWS architecture happening @skillsmatter. +
+
+
From f29e5dc8a15d0ab8e9c6084e41ee373376051659 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Thu, 16 May 2013 12:09:06 -0700 Subject: [PATCH 04/95] Remove hijack from api when not necessary --- api.go | 40 ++++++++-------------------------------- commands.go | 23 +++++++++++++---------- registry/registry.go | 1 - server.go | 11 ++++++----- 4 files changed, 27 insertions(+), 48 deletions(-) diff --git a/api.go b/api.go index 8984d00cd..4cfb0aac7 100644 --- a/api.go +++ b/api.go @@ -283,23 +283,17 @@ func postImagesCreate(srv *Server, w http.ResponseWriter, r *http.Request, vars src := r.Form.Get("fromSrc") image := r.Form.Get("fromImage") - repo := r.Form.Get("repo") tag := r.Form.Get("tag") + repo := r.Form.Get("repo") - in, out, err := hijackServer(w) - if err != nil { - return err - } - defer in.Close() - fmt.Fprintf(out, "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.docker.raw-stream\r\n\r\n") if image != "" { //pull registry := r.Form.Get("registry") - if err := srv.ImagePull(image, tag, registry, out); err != nil { - fmt.Fprintf(out, "Error: %s\n", err) + if err := srv.ImagePull(image, tag, registry, w); err != nil { + return err } } else { //import - if err := srv.ImageImport(src, repo, tag, in, out); err != nil { - fmt.Fprintf(out, "Error: %s\n", err) + if err := srv.ImageImport(src, repo, tag, r.Body, w); err != nil { + return err } } return nil @@ -335,15 +329,9 @@ func postImagesInsert(srv *Server, w http.ResponseWriter, r *http.Request, vars } name := vars["name"] - in, out, err := hijackServer(w) - if err != nil { + if err := srv.ImageInsert(name, url, path, w); err != nil { return err } - defer in.Close() - fmt.Fprintf(out, "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.docker.raw-stream\r\n\r\n") - if err := srv.ImageInsert(name, url, path, out); err != nil { - fmt.Fprintf(out, "Error: %s\n", err) - } return nil } @@ -358,28 +346,16 @@ func postImagesPush(srv *Server, w http.ResponseWriter, r *http.Request, vars ma } name := vars["name"] - in, out, err := hijackServer(w) - if err != nil { + if err := srv.ImagePush(name, registry, w); err != nil { return err } - defer in.Close() - fmt.Fprintf(out, "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.docker.raw-stream\r\n\r\n") - if err := srv.ImagePush(name, registry, out); err != nil { - fmt.Fprintf(out, "Error: %s\n", err) - } return nil } func postBuild(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - in, out, err := hijackServer(w) - if err != nil { + if err := srv.ImageCreateFromFile(r.Body, w); err != nil { return err } - defer in.Close() - fmt.Fprintf(out, "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.docker.raw-stream\r\n\r\n") - if err := srv.ImageCreateFromFile(in, out); err != nil { - fmt.Fprintf(out, "Error: %s\n", err) - } return nil } diff --git a/commands.go b/commands.go index 8734da176..cbd9d146f 100644 --- a/commands.go +++ b/commands.go @@ -104,7 +104,7 @@ func (cli *DockerCli) CmdInsert(args ...string) error { v.Set("url", cmd.Arg(1)) v.Set("path", cmd.Arg(2)) - err := cli.hijack("POST", "/images/"+cmd.Arg(0)+"?"+v.Encode(), false) + err := cli.stream("POST", "/images/"+cmd.Arg(0)+"?"+v.Encode(), nil, os.Stdout) if err != nil { return err } @@ -117,7 +117,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error { return nil } - err := cli.hijack("POST", "/build", false) + err := cli.stream("POST", "/build", nil, os.Stdout) if err != nil { return err } @@ -571,7 +571,7 @@ func (cli *DockerCli) CmdImport(args ...string) error { v.Set("tag", tag) v.Set("fromSrc", src) - err := cli.hijack("POST", "/images/create?"+v.Encode(), false) + err := cli.stream("POST", "/images/create?"+v.Encode(), os.Stdin, os.Stdout) if err != nil { return err } @@ -628,7 +628,7 @@ func (cli *DockerCli) CmdPush(args ...string) error { v := url.Values{} v.Set("registry", *registry) - if err := cli.hijack("POST", "/images/"+name+"/push?"+v.Encode(), false); err != nil { + if err := cli.stream("POST", "/images/"+name+"/push?"+v.Encode(), nil, os.Stdout); err != nil { return err } return nil @@ -659,7 +659,7 @@ func (cli *DockerCli) CmdPull(args ...string) error { v.Set("tag", *tag) v.Set("registry", *registry) - if err := cli.hijack("POST", "/images/create?"+v.Encode(), false); err != nil { + if err := cli.stream("POST", "/images/create?"+v.Encode(), nil, os.Stdout); err != nil { return err } @@ -864,7 +864,7 @@ func (cli *DockerCli) CmdExport(args ...string) error { return nil } - if err := cli.stream("GET", "/containers/"+cmd.Arg(0)+"/export"); err != nil { + if err := cli.stream("GET", "/containers/"+cmd.Arg(0)+"/export", nil, os.Stdout); err != nil { return err } return nil @@ -1086,7 +1086,7 @@ func (cli *DockerCli) CmdRun(args ...string) error { if statusCode == 404 { v := url.Values{} v.Set("fromImage", config.Image) - err = cli.hijack("POST", "/images/create?"+v.Encode(), false) + err = cli.stream("POST", "/images/create?"+v.Encode(), nil, os.Stderr) if err != nil { return err } @@ -1179,8 +1179,11 @@ func (cli *DockerCli) call(method, path string, data interface{}) ([]byte, int, return body, resp.StatusCode, nil } -func (cli *DockerCli) stream(method, path string) error { - req, err := http.NewRequest(method, fmt.Sprintf("http://%s:%d%s", cli.host, cli.port, path), nil) +func (cli *DockerCli) stream(method, path string, in io.Reader, out io.Writer) error { + 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) if err != nil { return err } @@ -1204,7 +1207,7 @@ func (cli *DockerCli) stream(method, path string) error { return fmt.Errorf("error: %s", body) } - if _, err := io.Copy(os.Stdout, resp.Body); err != nil { + if _, err := io.Copy(out, resp.Body); err != nil { return err } return nil diff --git a/registry/registry.go b/registry/registry.go index e2ffb292c..71648d180 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -175,7 +175,6 @@ func (r *Registry) GetRemoteTags(registries []string, repository string, token [ } func (r *Registry) GetRepositoryData(remote string) (*RepositoryData, error) { - utils.Debugf("Pulling repository %s from %s\r\n", remote, auth.IndexServerAddress()) repositoryTarget := auth.IndexServerAddress() + "/repositories/" + remote + "/images" req, err := http.NewRequest("GET", repositoryTarget, nil) diff --git a/server.go b/server.go index 2f45802ca..f6a242606 100644 --- a/server.go +++ b/server.go @@ -2,6 +2,7 @@ package docker import ( "fmt" + "github.com/dotcloud/docker/auth" "github.com/dotcloud/docker/registry" "github.com/dotcloud/docker/utils" "io" @@ -322,8 +323,8 @@ func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []stri return nil } -func (srv *Server) pullRepository(stdout io.Writer, remote, askedTag string) error { - utils.Debugf("Retrieving repository data") +func (srv *Server) pullRepository(out io.Writer, remote, askedTag string) error { + fmt.Fprintf(out, "Pulling repository %s from %s\r\n", remote, auth.IndexServerAddress()) repoData, err := srv.registry.GetRepositoryData(remote) if err != nil { return err @@ -349,11 +350,11 @@ func (srv *Server) pullRepository(stdout io.Writer, remote, askedTag string) err if askedTag != "" && askedTag != img.Tag { continue } - fmt.Fprintf(stdout, "Pulling image %s (%s) from %s\n", img.Id, img.Tag, remote) + fmt.Fprintf(out, "Pulling image %s (%s) from %s\n", img.Id, img.Tag, remote) success := false for _, ep := range repoData.Endpoints { - if err := srv.pullImage(stdout, img.Id, "https://"+ep+"/v1", repoData.Tokens); err != nil { - fmt.Fprintf(stdout, "Error while retrieving image for tag: %s (%s); checking next endpoint\n", askedTag, err) + if err := srv.pullImage(out, img.Id, "https://"+ep+"/v1", repoData.Tokens); err != nil { + fmt.Fprintf(out, "Error while retrieving image for tag: %s (%s); checking next endpoint\n", askedTag, err) continue } if err := srv.runtime.repositories.Set(remote, img.Tag, img.Id, true); err != nil { From 6145812444fb3eda2cc362795ed0b1addb8f4847 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Thu, 16 May 2013 14:33:10 -0700 Subject: [PATCH 05/95] Update tests to reflect new behavior --- api_test.go | 53 +++++++++++++++++++---------------------------------- commands.go | 2 +- 2 files changed, 20 insertions(+), 35 deletions(-) diff --git a/api_test.go b/api_test.go index 07ecc6d0b..0827c9b5a 100644 --- a/api_test.go +++ b/api_test.go @@ -14,6 +14,7 @@ import ( "net/http/httptest" "os" "path" + "strings" "testing" "time" ) @@ -587,45 +588,29 @@ func TestPostBuild(t *testing.T) { srv := &Server{runtime: runtime} - stdin, stdinPipe := io.Pipe() - stdout, stdoutPipe := io.Pipe() + imgs, err := runtime.graph.All() + if err != nil { + t.Fatal(err) + } + beginCount := len(imgs) - c1 := make(chan struct{}) - go func() { - defer close(c1) - r := &hijackTester{ - ResponseRecorder: httptest.NewRecorder(), - in: stdin, - out: stdoutPipe, - } - - if err := postBuild(srv, r, nil, nil); err != nil { - t.Fatal(err) - } - }() - - // Acknowledge hijack - setTimeout(t, "hijack acknowledge timed out", 2*time.Second, func() { - stdout.Read([]byte{}) - stdout.Read(make([]byte, 4096)) - }) - - setTimeout(t, "read/write assertion timed out", 2*time.Second, func() { - if err := assertPipe("from docker-ut\n", "FROM docker-ut", stdout, stdinPipe, 15); err != nil { - t.Fatal(err) - } - }) - - // Close pipes (client disconnects) - if err := closeWrap(stdin, stdinPipe, stdout, stdoutPipe); err != nil { + req, err := http.NewRequest("POST", "/build", strings.NewReader(Dockerfile)) + if err != nil { t.Fatal(err) } - // Wait for build to finish, the client disconnected, therefore, Build finished his job - setTimeout(t, "Waiting for CmdBuild timed out", 2*time.Second, func() { - <-c1 - }) + r := httptest.NewRecorder() + if err := postBuild(srv, r, req, nil); err != nil { + t.Fatal(err) + } + imgs, err = runtime.graph.All() + if err != nil { + t.Fatal(err) + } + if len(imgs) != beginCount+3 { + t.Fatalf("Expected %d images, %d found", beginCount+3, len(imgs)) + } } func TestPostImagesCreate(t *testing.T) { diff --git a/commands.go b/commands.go index cbd9d146f..4567370d3 100644 --- a/commands.go +++ b/commands.go @@ -117,7 +117,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error { return nil } - err := cli.stream("POST", "/build", nil, os.Stdout) + err := cli.stream("POST", "/build", os.Stdin, os.Stdout) if err != nil { return err } From 08121c8f6b435779027d837c1e7fc8046bc1e165 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Thu, 16 May 2013 14:33:29 -0700 Subject: [PATCH 06/95] Update Push to reflect the correct API --- registry/registry.go | 48 ++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/registry/registry.go b/registry/registry.go index 71648d180..ce9b4b4ac 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -326,10 +326,11 @@ func (r *Registry) PushImageJsonIndex(remote string, imgList []*ImgData, validat if err != nil { return nil, err } - - utils.Debugf("json sent: %s\n", imgListJson) - - req, err := http.NewRequest("PUT", auth.IndexServerAddress()+"/repositories/"+remote+"/", bytes.NewReader(imgListJson)) + var suffix string + if validate { + suffix = "images" + } + req, err := http.NewRequest("PUT", auth.IndexServerAddress()+"/repositories/"+remote+"/"+suffix, bytes.NewReader(imgListJson)) if err != nil { return nil, err } @@ -361,29 +362,28 @@ func (r *Registry) PushImageJsonIndex(remote string, imgList []*ImgData, validat defer res.Body.Close() } - if res.StatusCode != 200 && res.StatusCode != 201 { - errBody, err := ioutil.ReadAll(res.Body) - if err != nil { - return nil, err + var tokens, endpoints []string + if !validate { + if res.StatusCode != 200 && res.StatusCode != 201 { + errBody, err := ioutil.ReadAll(res.Body) + if err != nil { + return nil, err + } + return nil, fmt.Errorf("Error: Status %d trying to push repository %s: %s", res.StatusCode, remote, errBody) + } + if res.Header.Get("X-Docker-Token") != "" { + tokens = res.Header["X-Docker-Token"] + utils.Debugf("Auth token: %v", tokens) + } else { + return nil, fmt.Errorf("Index response didn't contain an access token") } - return nil, fmt.Errorf("Error: Status %d trying to push repository %s: %s", res.StatusCode, remote, errBody) - } - var tokens []string - if res.Header.Get("X-Docker-Token") != "" { - tokens = res.Header["X-Docker-Token"] - utils.Debugf("Auth token: %v", tokens) - } else { - return nil, fmt.Errorf("Index response didn't contain an access token") + if res.Header.Get("X-Docker-Endpoints") != "" { + endpoints = res.Header["X-Docker-Endpoints"] + } else { + return nil, fmt.Errorf("Index response didn't contain any endpoints") + } } - - var endpoints []string - if res.Header.Get("X-Docker-Endpoints") != "" { - endpoints = res.Header["X-Docker-Endpoints"] - } else { - return nil, fmt.Errorf("Index response didn't contain any endpoints") - } - if validate { if res.StatusCode != 204 { if errBody, err := ioutil.ReadAll(res.Body); err != nil { From 1b0b962b43afe2f0e07b31fe03e64db4e7d97854 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Fri, 17 May 2013 13:23:12 +0000 Subject: [PATCH 07/95] add login check before pull user's repo --- commands.go | 71 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 28 deletions(-) diff --git a/commands.go b/commands.go index 8734da176..db073f7d4 100644 --- a/commands.go +++ b/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 72360b2cdfcfb70e72295b8f8cf7618257ce8826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Petazzoni?= Date: Fri, 17 May 2013 05:46:32 -0700 Subject: [PATCH 08/95] Add information about kernel requirements This page will be helpful for people who: - want run run a custom kernel - want to enable memory/swap accounting on Debian/Ubuntu --- docs/sources/installation/index.rst | 1 + docs/sources/installation/kernel.rst | 126 +++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 docs/sources/installation/kernel.rst diff --git a/docs/sources/installation/index.rst b/docs/sources/installation/index.rst index 698d7f8ff..1976f30ba 100644 --- a/docs/sources/installation/index.rst +++ b/docs/sources/installation/index.rst @@ -20,3 +20,4 @@ Contents: rackspace archlinux upgrading + kernel diff --git a/docs/sources/installation/kernel.rst b/docs/sources/installation/kernel.rst new file mode 100644 index 000000000..30ea192b1 --- /dev/null +++ b/docs/sources/installation/kernel.rst @@ -0,0 +1,126 @@ +.. _kernel: + +Kernel Requirements +=================== + + The officially supported kernel is the one recommended by the + :ref:`ubuntu_linux` installation path. It is the one that most developers + will use, and the one that receives the most attention from the core + contributors. If you decide to go with a different kernel and hit a bug, + please try to reproduce it with the official kernels first. + +If for some reason you cannot or do not want to use the "official" kernels, +here is some technical background about the features (both optional and +mandatory) that docker needs to run successfully. + +In short, you need kernel version 3.8 (or above), compiled to include +`AUFS support `_. Of course, you need to +enable cgroups and namespaces. + + +Namespaces and Cgroups +---------------------- + +You need to enable namespaces and cgroups, to the extend of what is needed +to run LXC containers. Technically, while namespaces have been introduced +in the early 2.6 kernels, we do not advise to try any kernel before 2.6.32 +to run LXC containers. Note that 2.6.32 has some documented issues regarding +network namespace setup and teardown; those issues are not a risk if you +run containers in a private environment, but can lead to denial-of-service +attacks if you want to run untrusted code in your containers. For more details, +see `[LP#720095 `_. + +Kernels 2.6.38, and every version since 3.2, have been deployed successfully +to run containerized production workloads. Feature-wise, there is no huge +improvement between 2.6.38 and up to 3.6 (as far as docker is concerned!). + +Starting with version 3.7, the kernel has basic support for +`Checkpoint/Restore In Userspace `_, which is not used by +docker at this point, but allows to suspend the state of a container to +disk and resume it later. + +Version 3.8 provides improvements in stability, which are deemed necessary +for the operation of docker. Versions 3.2 to 3.5 have been shown to +exhibit a reproducible bug (for more details, see issue +`#407 `_). + +Version 3.8 also brings better support for the +`setns() syscall `_ -- but this should not +be a concern since docker does not leverage on this feature for now. + +If you want a technical overview about those concepts, you might +want to check those articles on dotCloud's blog: +`about namespaces `_ +and `about cgroups `_. + + +Extra Cgroup Controllers +------------------------ + +Most control groups can be enabled or disabled individually. For instance, +you can decide that you do not want to compile support for the CPU or memory +controller. In some cases, the feature can be enabled or disabled at boot +time. It is worth mentioning that some distributions (like Debian) disable +"expensive" features, like the memory controller, because they can have +a significant performance impact. + +In the specific case of the memory cgroup, docker will detect if the cgroup +is available or not. If it's not, it will print a warning, and it won't +use the feature. If you want to enable that feature -- read on! + + +Memory and Swap Accounting on Debian/Ubuntu +------------------------------------------- + +If you use Debian or Ubuntu kernels, and want to enable memory and swap +accounting, you must add the following command-line parameters to your kernel:: + + cgroup_enable=memory swapaccount + +On Debian or Ubuntu systems, if you use the default GRUB bootloader, you can +add those parameters by editing ``/etc/default/grub`` and extending +``GRUB_CMDLINE_LINUX``. Look for the following line:: + + GRUB_CMDLINE_LINUX="" + +And replace it by the following one:: + + GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount" + +Then run ``update-grub``, and reboot. + + +AUFS +---- + +Docker currently relies on AUFS, an unioning filesystem. +While AUFS is included in the kernels built by the Debian and Ubuntu +distributions, is not part of the standard kernel. This means that if +you decide to roll your own kernel, you will have to patch your +kernel tree to add AUFS. The process is documented on +`AUFS webpage `_. + +Note: the AUFS patch is fairly intrusive, but for the record, people have +successfully applied GRSEC and AUFS together, to obtain hardened production +kernels. + +If you want more information about that topic, there is an +`article about AUFS on dotCloud's blog +`_. + + +BTRFS, ZFS, OverlayFS... +------------------------ + +There is ongoing development on docker, to implement support for +`BTRFS `_ +(see github issue `#443 `_). + +People have also showed interest for `ZFS `_ +(using e.g. `ZFS-on-Linux `_) and OverlayFS. +The latter is functionally close to AUFS, and it might end up being included +in the stock kernel; so it's a strong candidate! + +Would you like to `contribute +`_ +support for your favorite filesystem? From 6301373c68990e8a92730de23a4da86b3442b4ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Petazzoni?= Date: Fri, 17 May 2013 10:20:30 -0700 Subject: [PATCH 09/95] Add some details about pre-3.8 kernels --- docs/sources/installation/kernel.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/sources/installation/kernel.rst b/docs/sources/installation/kernel.rst index 30ea192b1..2ec5940a7 100644 --- a/docs/sources/installation/kernel.rst +++ b/docs/sources/installation/kernel.rst @@ -54,6 +54,29 @@ want to check those articles on dotCloud's blog: and `about cgroups `_. +Important Note About Pre-3.8 Kernels +------------------------------------ + +As mentioned above, kernels before 3.8 are not stable when used with docker. +In some circumstances, you will experience kernel "oopses", or even crashes. +The symptoms include: + +- a container being killed in the middle of an operation (e.g. an ``apt-get`` + command doesn't complete); +- kernel messages including mentioning calls to ``mntput`` or + ``d_hash_and_lookup``; +- kernel crash causing the machine to freeze for a few minutes, or even + completely. + +While it is still possible to use older kernels for development, it is +really not advised to do so. + +Docker checks the kernel version when it starts, and emits a warning if it +detects something older than 3.8. + +See issue `#407 `_ for details. + + Extra Cgroup Controllers ------------------------ From 0143be42a13b9f8082ceddc64a5e523e45f54d88 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Sat, 18 May 2013 14:03:53 +0000 Subject: [PATCH 10/95] add flush after each write when needed --- server.go | 36 ++++++++++++++++++------------------ utils/utils.go | 15 ++++++++++++--- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/server.go b/server.go index f6a242606..6576fac0d 100644 --- a/server.go +++ b/server.go @@ -98,7 +98,7 @@ func (srv *Server) ImageInsert(name, url, path string, out io.Writer) error { if err != nil { return err } - fmt.Fprintf(out, "%s\n", img.Id) + utils.FprintfFlush(out, "%s\n", img.Id) return nil } @@ -298,7 +298,7 @@ func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []stri // FIXME: Launch the getRemoteImage() in goroutines for _, id := range history { if !srv.runtime.graph.Exists(id) { - fmt.Fprintf(out, "Pulling %s metadata\r\n", id) + utils.FprintfFlush(out, "Pulling %s metadata\r\n", id) imgJson, err := srv.registry.GetRemoteImageJson(id, registry, token) if err != nil { // FIXME: Keep goging in case of error? @@ -310,7 +310,7 @@ func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []stri } // Get the layer - fmt.Fprintf(out, "Pulling %s fs layer\r\n", img.Id) + utils.FprintfFlush(out, "Pulling %s fs layer\r\n", img.Id) layer, contentLength, err := srv.registry.GetRemoteImageLayer(img.Id, registry, token) if err != nil { return err @@ -324,7 +324,7 @@ func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []stri } func (srv *Server) pullRepository(out io.Writer, remote, askedTag string) error { - fmt.Fprintf(out, "Pulling repository %s from %s\r\n", remote, auth.IndexServerAddress()) + utils.FprintfFlush(out, "Pulling repository %s from %s\r\n", remote, auth.IndexServerAddress()) repoData, err := srv.registry.GetRepositoryData(remote) if err != nil { return err @@ -350,11 +350,11 @@ func (srv *Server) pullRepository(out io.Writer, remote, askedTag string) error if askedTag != "" && askedTag != img.Tag { continue } - fmt.Fprintf(out, "Pulling image %s (%s) from %s\n", img.Id, img.Tag, remote) + utils.FprintfFlush(out, "Pulling image %s (%s) from %s\n", img.Id, img.Tag, remote) success := false for _, ep := range repoData.Endpoints { if err := srv.pullImage(out, img.Id, "https://"+ep+"/v1", repoData.Tokens); err != nil { - fmt.Fprintf(out, "Error while retrieving image for tag: %s (%s); checking next endpoint\n", askedTag, err) + utils.FprintfFlush(out, "Error while retrieving image for tag: %s (%s); checking next endpoint\n", askedTag, err) continue } if err := srv.runtime.repositories.Set(remote, img.Tag, img.Id, true); err != nil { @@ -462,12 +462,12 @@ func (srv *Server) getImageList(localRepo map[string]string) ([]*registry.ImgDat } func (srv *Server) pushRepository(out io.Writer, name string, localRepo map[string]string) error { - fmt.Fprintf(out, "Processing checksums\n") + utils.FprintfFlush(out, "Processing checksums\n") imgList, err := srv.getImageList(localRepo) if err != nil { return err } - fmt.Fprintf(out, "Sending image list\n") + utils.FprintfFlush(out, "Sending image list\n") repoData, err := srv.registry.PushImageJsonIndex(name, imgList, false) if err != nil { @@ -476,18 +476,18 @@ func (srv *Server) pushRepository(out io.Writer, name string, localRepo map[stri // FIXME: Send only needed images for _, ep := range repoData.Endpoints { - fmt.Fprintf(out, "Pushing repository %s to %s (%d tags)\r\n", name, ep, len(localRepo)) + utils.FprintfFlush(out, "Pushing repository %s to %s (%d tags)\r\n", name, ep, len(localRepo)) // For each image within the repo, push them for _, elem := range imgList { if _, exists := repoData.ImgList[elem.Id]; exists { - fmt.Fprintf(out, "Image %s already on registry, skipping\n", name) + utils.FprintfFlush(out, "Image %s already on registry, skipping\n", name) continue } if err := srv.pushImage(out, name, elem.Id, ep, repoData.Tokens); err != nil { // FIXME: Continue on error? return err } - fmt.Fprintf(out, "Pushing tags for rev [%s] on {%s}\n", elem.Id, ep+"/users/"+name+"/"+elem.Tag) + utils.FprintfFlush(out, "Pushing tags for rev [%s] on {%s}\n", elem.Id, ep+"/users/"+name+"/"+elem.Tag) if err := srv.registry.PushRegistryTag(name, elem.Id, elem.Tag, ep, repoData.Tokens); err != nil { return err } @@ -505,7 +505,7 @@ func (srv *Server) pushImage(out io.Writer, remote, imgId, ep string, token []st if err != nil { return fmt.Errorf("Error while retreiving the path for {%s}: %s", imgId, err) } - fmt.Fprintf(out, "Pushing %s\r\n", imgId) + utils.FprintfFlush(out, "Pushing %s\r\n", imgId) // Make sure we have the image's checksum checksum, err := srv.getChecksum(imgId) @@ -520,7 +520,7 @@ func (srv *Server) pushImage(out io.Writer, remote, imgId, ep string, token []st // Send the json if err := srv.registry.PushImageJsonRegistry(imgData, jsonRaw, ep, token); err != nil { if err == registry.ErrAlreadyExists { - fmt.Fprintf(out, "Image %s already uploaded ; skipping\n", imgData.Id) + utils.FprintfFlush(out, "Image %s already uploaded ; skipping\n", imgData.Id) return nil } return err @@ -562,7 +562,7 @@ func (srv *Server) pushImage(out io.Writer, remote, imgId, ep string, token []st func (srv *Server) ImagePush(name, registry string, out io.Writer) error { img, err := srv.runtime.graph.Get(name) if err != nil { - fmt.Fprintf(out, "The push refers to a repository [%s] (len: %d)\n", name, len(srv.runtime.repositories.Repositories[name])) + utils.FprintfFlush(out, "The push refers to a repository [%s] (len: %d)\n", name, len(srv.runtime.repositories.Repositories[name])) // If it fails, try to get the repository if localRepo, exists := srv.runtime.repositories.Repositories[name]; exists { if err := srv.pushRepository(out, name, localRepo); err != nil { @@ -573,7 +573,7 @@ func (srv *Server) ImagePush(name, registry string, out io.Writer) error { return err } - fmt.Fprintf(out, "The push refers to an image: [%s]\n", name) + utils.FprintfFlush(out, "The push refers to an image: [%s]\n", name) if err := srv.pushImage(out, name, img.Id, registry, nil); err != nil { return err } @@ -589,14 +589,14 @@ func (srv *Server) ImageImport(src, repo, tag string, in io.Reader, out io.Write } else { u, err := url.Parse(src) if err != nil { - fmt.Fprintf(out, "Error: %s\n", err) + utils.FprintfFlush(out, "Error: %s\n", err) } if u.Scheme == "" { u.Scheme = "http" u.Host = src u.Path = "" } - fmt.Fprintln(out, "Downloading from", u) + utils.FprintfFlush(out, "Downloading from %s\n", u) // Download with curl (pretty progress bar) // If curl is not available, fallback to http.Get() resp, err = utils.Download(u.String(), out) @@ -615,7 +615,7 @@ func (srv *Server) ImageImport(src, repo, tag string, in io.Reader, out io.Write return err } } - fmt.Fprintln(out, img.ShortId()) + utils.FprintfFlush(out, "%s\n", img.ShortId()) return nil } diff --git a/utils/utils.go b/utils/utils.go index 88d0c87f5..6a6a9f95b 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -84,15 +84,15 @@ func (r *progressReader) Read(p []byte) (n int, err error) { } if r.readProgress-r.lastUpdate > updateEvery || err != nil { if r.readTotal > 0 { - fmt.Fprintf(r.output, r.template+"\r", r.readProgress, r.readTotal, fmt.Sprintf("%.0f%%", float64(r.readProgress)/float64(r.readTotal)*100)) + FprintfFlush(r.output, r.template+"\r", r.readProgress, r.readTotal, fmt.Sprintf("%.0f%%", float64(r.readProgress)/float64(r.readTotal)*100)) } else { - fmt.Fprintf(r.output, r.template+"\r", r.readProgress, "?", "n/a") + FprintfFlush(r.output, r.template+"\r", r.readProgress, "?", "n/a") } r.lastUpdate = r.readProgress } // Send newline when complete if err != nil { - fmt.Fprintf(r.output, "\n") + FprintfFlush(r.output, "\n") } return read, err @@ -530,3 +530,12 @@ func GetKernelVersion() (*KernelVersionInfo, error) { Flavor: flavor, }, nil } + + +func FprintfFlush(w io.Writer, format string, a ...interface{}) (n int, err error) { + n, err = fmt.Fprintf(w, format, a...) + if f, ok := w.(http.Flusher); ok { + f.Flush() + } + return n, err +} \ No newline at end of file From 2b55874584f034b5113359ced6b05c143d31e03c Mon Sep 17 00:00:00 2001 From: Francisco Souza Date: Sat, 18 May 2013 22:55:59 -0300 Subject: [PATCH 11/95] utils: fix compilation on Darwin Although Docker daemon does not work on Darwin, the API client will have to work. That said, I'm fixing the compilation of the package on Darwin. --- utils/uname_darwin.go | 7 +++++-- utils/uname_linux.go | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/utils/uname_darwin.go b/utils/uname_darwin.go index d799554bb..a875e8c60 100644 --- a/utils/uname_darwin.go +++ b/utils/uname_darwin.go @@ -2,9 +2,12 @@ package utils import ( "errors" - "syscall" ) -func uname() (*syscall.Utsname, error) { +type Utsname struct { + Release [65]byte +} + +func uname() (*Utsname, error) { return nil, errors.New("Kernel version detection is not available on darwin") } diff --git a/utils/uname_linux.go b/utils/uname_linux.go index 675a89b00..6e47bcc82 100644 --- a/utils/uname_linux.go +++ b/utils/uname_linux.go @@ -4,8 +4,9 @@ import ( "syscall" ) -// FIXME: Move this to utils package -func uname() (*syscall.Utsname, error) { +type Utsname syscall.Utsname + +func uname() (*Utsname, error) { uts := &syscall.Utsname{} if err := syscall.Uname(uts); err != nil { From ea7fdecd41a107d038503578324197780df002a8 Mon Sep 17 00:00:00 2001 From: Phil Spitler Date: Sun, 19 May 2013 09:37:02 -0300 Subject: [PATCH 12/95] Fixed typo in remote API doc --- docs/sources/api/docker_remote_api.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sources/api/docker_remote_api.rst b/docs/sources/api/docker_remote_api.rst index 03f1d4b9c..1dee086d0 100644 --- a/docs/sources/api/docker_remote_api.rst +++ b/docs/sources/api/docker_remote_api.rst @@ -9,7 +9,7 @@ Docker Remote API - The Remote API is replacing rcli - Default port in the docker deamon is 4243 -- The API tends to be REST, but for some complex commands, like attach or pull, the HTTP connection in hijacked to transport stdout stdin and stderr +- The API tends to be REST, but for some complex commands, like attach or pull, the HTTP connection is hijacked to transport stdout stdin and stderr 2. Endpoints ============ From 8291f8b85ca653e13f17ffb126b57bb6b40c1cb5 Mon Sep 17 00:00:00 2001 From: Francisco Souza Date: Sun, 19 May 2013 11:57:45 -0300 Subject: [PATCH 13/95] docs/remote_api: remove trunc_cmd from /containers/ps example Apparently, this parameter does not exist anymore. --- docs/sources/api/docker_remote_api.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sources/api/docker_remote_api.rst b/docs/sources/api/docker_remote_api.rst index 1dee086d0..2b1aad0e8 100644 --- a/docs/sources/api/docker_remote_api.rst +++ b/docs/sources/api/docker_remote_api.rst @@ -28,7 +28,7 @@ List containers .. sourcecode:: http - GET /containers/ps?trunc_cmd=0&all=1&before=8dfafdbc3a40 HTTP/1.1 + GET /containers/ps?all=1&before=8dfafdbc3a40 HTTP/1.1 **Example response**: From 0b785487fe752cc4111a3f0005a2ae090b30c52b Mon Sep 17 00:00:00 2001 From: Kiran Gangadharan Date: Sun, 19 May 2013 21:04:34 +0530 Subject: [PATCH 14/95] Fixed typos --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1f69e4d83..c83feeae5 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ for containerization, including Linux with [openvz](http://openvz.org), [vserver Docker builds on top of these low-level primitives to offer developers a portable format and runtime environment that solves all 4 problems. Docker containers are small (and their transfer can be optimized with layers), they have basically zero memory and cpu overhead, -the are completely portable and are designed from the ground up with an application-centric design. +they are completely portable and are designed from the ground up with an application-centric design. The best part: because docker operates at the OS level, it can still be run inside a VM! @@ -46,7 +46,7 @@ Docker does not require that you buy into a particular programming language, fra Is your application a unix process? Does it use files, tcp connections, environment variables, standard unix streams and command-line arguments as inputs and outputs? Then docker can run it. -Can your application's build be expressed a sequence of such commands? Then docker can build it. +Can your application's build be expressed as a sequence of such commands? Then docker can build it. ## Escape dependency hell @@ -70,7 +70,7 @@ Docker solves dependency hell by giving the developer a simple way to express *a and streamline the process of assembling them. If this makes you think of [XKCD 927](http://xkcd.com/927/), don't worry. Docker doesn't *replace* your favorite packaging systems. It simply orchestrates their use in a simple and repeatable way. How does it do that? With layers. -Docker defines a build as running a sequence unix commands, one after the other, in the same container. Build commands modify the contents of the container +Docker defines a build as running a sequence of unix commands, one after the other, in the same container. Build commands modify the contents of the container (usually by installing new files on the filesystem), the next command modifies it some more, etc. Since each build command inherits the result of the previous commands, the *order* in which the commands are executed expresses *dependencies*. @@ -293,7 +293,7 @@ a format that is self-describing and portable, so that any compliant runtime can The spec for Standard Containers is currently a work in progress, but it is very straightforward. It mostly defines 1) an image format, 2) a set of standard operations, and 3) an execution environment. -A great analogy for this is the shipping container. Just like Standard Containers are a fundamental unit of software delivery, shipping containers (http://bricks.argz.com/ins/7823-1/12) are a fundamental unit of physical delivery. +A great analogy for this is the shipping container. Just like how Standard Containers are a fundamental unit of software delivery, shipping containers (http://bricks.argz.com/ins/7823-1/12) are a fundamental unit of physical delivery. ### 1. STANDARD OPERATIONS @@ -321,7 +321,7 @@ Similarly, before Standard Containers, by the time a software component ran in p ### 5. INDUSTRIAL-GRADE DELIVERY -There are 17 million shipping containers in existence, packed with every physical good imaginable. Every single one of them can be loaded on the same boats, by the same cranes, in the same facilities, and sent anywhere in the World with incredible efficiency. It is embarrassing to think that a 30 ton shipment of coffee can safely travel half-way across the World in *less time* than it takes a software team to deliver its code from one datacenter to another sitting 10 miles away. +There are 17 million shipping containers in existence, packed with every physical good imaginable. Every single one of them can be loaded onto the same boats, by the same cranes, in the same facilities, and sent anywhere in the World with incredible efficiency. It is embarrassing to think that a 30 ton shipment of coffee can safely travel half-way across the World in *less time* than it takes a software team to deliver its code from one datacenter to another sitting 10 miles away. With Standard Containers we can put an end to that embarrassment, by making INDUSTRIAL-GRADE DELIVERY of software a reality. From 0f312113d3ce37d57fb28eb98c8abcdcbfcd39a3 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Sun, 19 May 2013 10:46:24 -0700 Subject: [PATCH 15/95] Move docker build to client --- api.go | 34 +++-- api_params.go | 5 + builder.go | 358 +--------------------------------------------- builder_client.go | 275 +++++++++++++++++++++++++++++++++++ commands.go | 82 ++++++----- server.go | 47 ++++-- utils.go | 39 +++++ 7 files changed, 426 insertions(+), 414 deletions(-) create mode 100644 builder_client.go diff --git a/api.go b/api.go index 8984d00cd..5cb3da85c 100644 --- a/api.go +++ b/api.go @@ -370,19 +370,6 @@ func postImagesPush(srv *Server, w http.ResponseWriter, r *http.Request, vars ma return nil } -func postBuild(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - in, out, err := hijackServer(w) - if err != nil { - return err - } - defer in.Close() - fmt.Fprintf(out, "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.docker.raw-stream\r\n\r\n") - if err := srv.ImageCreateFromFile(in, out); err != nil { - fmt.Fprintf(out, "Error: %s\n", err) - } - return nil -} - func postContainersCreate(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { config := &Config{} if err := json.NewDecoder(r.Body).Decode(config); err != nil { @@ -593,6 +580,25 @@ func getImagesByName(srv *Server, w http.ResponseWriter, r *http.Request, vars m return nil } +func postImagesGetCache(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { + apiConfig := &ApiImageConfig{} + if err := json.NewDecoder(r.Body).Decode(apiConfig); err != nil { + return err + } + + image, err := srv.ImageGetCached(apiConfig.Id, apiConfig.Config) + if err != nil { + return err + } + apiId := &ApiId{Id: image.Id} + b, err := json.Marshal(apiId) + if err != nil { + return err + } + writeJson(w, b) + return nil +} + func ListenAndServe(addr string, srv *Server, logging bool) error { r := mux.NewRouter() log.Printf("Listening for HTTP on %s\n", addr) @@ -615,11 +621,11 @@ func ListenAndServe(addr string, srv *Server, logging bool) error { "POST": { "/auth": postAuth, "/commit": postCommit, - "/build": postBuild, "/images/create": postImagesCreate, "/images/{name:.*}/insert": postImagesInsert, "/images/{name:.*}/push": postImagesPush, "/images/{name:.*}/tag": postImagesTag, + "/images/getCache": postImagesGetCache, "/containers/create": postContainersCreate, "/containers/{name:.*}/kill": postContainersKill, "/containers/{name:.*}/restart": postContainersRestart, diff --git a/api_params.go b/api_params.go index e6f1c1b0b..1a24ab287 100644 --- a/api_params.go +++ b/api_params.go @@ -64,3 +64,8 @@ type ApiWait struct { type ApiAuth struct { Status string } + +type ApiImageConfig struct { + Id string + *Config +} diff --git a/builder.go b/builder.go index 149764477..5f56f65d0 100644 --- a/builder.go +++ b/builder.go @@ -1,14 +1,9 @@ package docker import ( - "bufio" - "encoding/json" "fmt" - "github.com/dotcloud/docker/utils" - "io" "os" "path" - "strings" "time" ) @@ -16,6 +11,9 @@ type Builder struct { runtime *Runtime repositories *TagStore graph *Graph + + config *Config + image *Image } func NewBuilder(runtime *Runtime) *Builder { @@ -26,45 +24,6 @@ func NewBuilder(runtime *Runtime) *Builder { } } -func (builder *Builder) mergeConfig(userConf, imageConf *Config) { - if userConf.Hostname != "" { - userConf.Hostname = imageConf.Hostname - } - if userConf.User != "" { - userConf.User = imageConf.User - } - if userConf.Memory == 0 { - userConf.Memory = imageConf.Memory - } - if userConf.MemorySwap == 0 { - userConf.MemorySwap = imageConf.MemorySwap - } - if userConf.CpuShares == 0 { - userConf.CpuShares = imageConf.CpuShares - } - if userConf.PortSpecs == nil || len(userConf.PortSpecs) == 0 { - userConf.PortSpecs = imageConf.PortSpecs - } - if !userConf.Tty { - userConf.Tty = imageConf.Tty - } - if !userConf.OpenStdin { - userConf.OpenStdin = imageConf.OpenStdin - } - if !userConf.StdinOnce { - userConf.StdinOnce = imageConf.StdinOnce - } - if userConf.Env == nil || len(userConf.Env) == 0 { - userConf.Env = imageConf.Env - } - if userConf.Cmd == nil || len(userConf.Cmd) == 0 { - userConf.Cmd = imageConf.Cmd - } - if userConf.Dns == nil || len(userConf.Dns) == 0 { - userConf.Dns = imageConf.Dns - } -} - func (builder *Builder) Create(config *Config) (*Container, error) { // Lookup image img, err := builder.repositories.LookupImage(config.Image) @@ -73,7 +32,7 @@ func (builder *Builder) Create(config *Config) (*Container, error) { } if img.Config != nil { - builder.mergeConfig(config, img.Config) + MergeConfig(config, img.Config) } if config.Cmd == nil || len(config.Cmd) == 0 { @@ -157,312 +116,3 @@ func (builder *Builder) Commit(container *Container, repository, tag, comment, a } return img, nil } - -func (builder *Builder) clearTmp(containers, images map[string]struct{}) { - for c := range containers { - tmp := builder.runtime.Get(c) - builder.runtime.Destroy(tmp) - utils.Debugf("Removing container %s", c) - } - for i := range images { - builder.runtime.graph.Delete(i) - utils.Debugf("Removing image %s", i) - } -} - -func (builder *Builder) getCachedImage(image *Image, config *Config) (*Image, error) { - // Retrieve all images - images, err := builder.graph.All() - if err != nil { - return nil, err - } - - // Store the tree in a map of map (map[parentId][childId]) - imageMap := make(map[string]map[string]struct{}) - for _, img := range images { - if _, exists := imageMap[img.Parent]; !exists { - imageMap[img.Parent] = make(map[string]struct{}) - } - imageMap[img.Parent][img.Id] = struct{}{} - } - - // Loop on the children of the given image and check the config - for elem := range imageMap[image.Id] { - img, err := builder.graph.Get(elem) - if err != nil { - return nil, err - } - if CompareConfig(&img.ContainerConfig, config) { - return img, nil - } - } - return nil, nil -} - -func (builder *Builder) Build(dockerfile io.Reader, stdout io.Writer) (*Image, error) { - var ( - image, base *Image - config *Config - maintainer string - env map[string]string = make(map[string]string) - tmpContainers map[string]struct{} = make(map[string]struct{}) - tmpImages map[string]struct{} = make(map[string]struct{}) - ) - defer builder.clearTmp(tmpContainers, tmpImages) - - file := bufio.NewReader(dockerfile) - for { - line, err := file.ReadString('\n') - if err != nil { - if err == io.EOF { - break - } - return nil, err - } - line = strings.Replace(strings.TrimSpace(line), " ", " ", 1) - // Skip comments and empty line - if len(line) == 0 || line[0] == '#' { - continue - } - tmp := strings.SplitN(line, " ", 2) - if len(tmp) != 2 { - return nil, fmt.Errorf("Invalid Dockerfile format") - } - instruction := strings.Trim(tmp[0], " ") - arguments := strings.Trim(tmp[1], " ") - switch strings.ToLower(instruction) { - case "from": - fmt.Fprintf(stdout, "FROM %s\n", arguments) - image, err = builder.runtime.repositories.LookupImage(arguments) - if err != nil { - // if builder.runtime.graph.IsNotExist(err) { - - // var tag, remote string - // if strings.Contains(arguments, ":") { - // remoteParts := strings.Split(arguments, ":") - // tag = remoteParts[1] - // remote = remoteParts[0] - // } else { - // remote = arguments - // } - - // panic("TODO: reimplement this") - // // if err := builder.runtime.graph.PullRepository(stdout, remote, tag, builder.runtime.repositories, builder.runtime.authConfig); err != nil { - // // return nil, err - // // } - - // image, err = builder.runtime.repositories.LookupImage(arguments) - // if err != nil { - // return nil, err - // } - // } else { - return nil, err - // } - } - config = &Config{} - - break - case "maintainer": - fmt.Fprintf(stdout, "MAINTAINER %s\n", arguments) - maintainer = arguments - break - case "run": - fmt.Fprintf(stdout, "RUN %s\n", arguments) - if image == nil { - return nil, fmt.Errorf("Please provide a source image with `from` prior to run") - } - config, _, err := ParseRun([]string{image.Id, "/bin/sh", "-c", arguments}, builder.runtime.capabilities) - if err != nil { - return nil, err - } - - for key, value := range env { - config.Env = append(config.Env, fmt.Sprintf("%s=%s", key, value)) - } - - if cache, err := builder.getCachedImage(image, config); err != nil { - return nil, err - } else if cache != nil { - image = cache - fmt.Fprintf(stdout, "===> %s\n", image.ShortId()) - break - } - - utils.Debugf("Env -----> %v ------ %v\n", config.Env, env) - - // Create the container and start it - c, err := builder.Create(config) - if err != nil { - return nil, err - } - - if os.Getenv("DEBUG") != "" { - out, _ := c.StdoutPipe() - err2, _ := c.StderrPipe() - go io.Copy(os.Stdout, out) - go io.Copy(os.Stdout, err2) - } - - if err := c.Start(); err != nil { - return nil, err - } - tmpContainers[c.Id] = struct{}{} - - // Wait for it to finish - if result := c.Wait(); result != 0 { - return nil, fmt.Errorf("!!! '%s' return non-zero exit code '%d'. Aborting.", arguments, result) - } - - // Commit the container - base, err = builder.Commit(c, "", "", "", maintainer, nil) - if err != nil { - return nil, err - } - tmpImages[base.Id] = struct{}{} - - fmt.Fprintf(stdout, "===> %s\n", base.ShortId()) - - // use the base as the new image - image = base - - break - case "env": - tmp := strings.SplitN(arguments, " ", 2) - if len(tmp) != 2 { - return nil, fmt.Errorf("Invalid ENV format") - } - key := strings.Trim(tmp[0], " ") - value := strings.Trim(tmp[1], " ") - fmt.Fprintf(stdout, "ENV %s %s\n", key, value) - env[key] = value - if image != nil { - fmt.Fprintf(stdout, "===> %s\n", image.ShortId()) - } else { - fmt.Fprintf(stdout, "===> \n") - } - break - case "cmd": - fmt.Fprintf(stdout, "CMD %s\n", arguments) - - // Create the container and start it - c, err := builder.Create(&Config{Image: image.Id, Cmd: []string{"", ""}}) - if err != nil { - return nil, err - } - if err := c.Start(); err != nil { - return nil, err - } - tmpContainers[c.Id] = struct{}{} - - cmd := []string{} - if err := json.Unmarshal([]byte(arguments), &cmd); err != nil { - return nil, err - } - config.Cmd = cmd - - // Commit the container - base, err = builder.Commit(c, "", "", "", maintainer, config) - if err != nil { - return nil, err - } - tmpImages[base.Id] = struct{}{} - - fmt.Fprintf(stdout, "===> %s\n", base.ShortId()) - image = base - break - case "expose": - ports := strings.Split(arguments, " ") - - fmt.Fprintf(stdout, "EXPOSE %v\n", ports) - if image == nil { - return nil, fmt.Errorf("Please provide a source image with `from` prior to copy") - } - - // Create the container and start it - c, err := builder.Create(&Config{Image: image.Id, Cmd: []string{"", ""}}) - if err != nil { - return nil, err - } - if err := c.Start(); err != nil { - return nil, err - } - tmpContainers[c.Id] = struct{}{} - - config.PortSpecs = append(ports, config.PortSpecs...) - - // Commit the container - base, err = builder.Commit(c, "", "", "", maintainer, config) - if err != nil { - return nil, err - } - tmpImages[base.Id] = struct{}{} - - fmt.Fprintf(stdout, "===> %s\n", base.ShortId()) - image = base - break - case "insert": - if image == nil { - return nil, fmt.Errorf("Please provide a source image with `from` prior to copy") - } - tmp = strings.SplitN(arguments, " ", 2) - if len(tmp) != 2 { - return nil, fmt.Errorf("Invalid INSERT format") - } - sourceUrl := strings.Trim(tmp[0], " ") - destPath := strings.Trim(tmp[1], " ") - fmt.Fprintf(stdout, "COPY %s to %s in %s\n", sourceUrl, destPath, base.ShortId()) - - file, err := utils.Download(sourceUrl, stdout) - if err != nil { - return nil, err - } - defer file.Body.Close() - - config, _, err := ParseRun([]string{base.Id, "echo", "insert", sourceUrl, destPath}, builder.runtime.capabilities) - if err != nil { - return nil, err - } - c, err := builder.Create(config) - if err != nil { - return nil, err - } - - if err := c.Start(); err != nil { - return nil, err - } - - // Wait for echo to finish - if result := c.Wait(); result != 0 { - return nil, fmt.Errorf("!!! '%s' return non-zero exit code '%d'. Aborting.", arguments, result) - } - - if err := c.Inject(file.Body, destPath); err != nil { - return nil, err - } - - base, err = builder.Commit(c, "", "", "", maintainer, nil) - if err != nil { - return nil, err - } - fmt.Fprintf(stdout, "===> %s\n", base.ShortId()) - - image = base - - break - default: - fmt.Fprintf(stdout, "Skipping unknown instruction %s\n", strings.ToUpper(instruction)) - } - } - if image != nil { - // The build is successful, keep the temporary containers and images - for i := range tmpImages { - delete(tmpImages, i) - } - for i := range tmpContainers { - delete(tmpContainers, i) - } - fmt.Fprintf(stdout, "Build finished. image id: %s\n", image.ShortId()) - return image, nil - } - return nil, fmt.Errorf("An error occured during the build\n") -} diff --git a/builder_client.go b/builder_client.go new file mode 100644 index 000000000..4a29129ed --- /dev/null +++ b/builder_client.go @@ -0,0 +1,275 @@ +package docker + +import ( + "bufio" + "encoding/json" + "fmt" + "github.com/dotcloud/docker/utils" + "io" + "net/url" + "os" + "reflect" + "strings" +) + +type BuilderClient struct { + builder *Builder + cli *DockerCli + + image string + maintainer string + config *Config + + tmpContainers map[string]struct{} + tmpImages map[string]struct{} + + needCommit bool +} + +func (b *BuilderClient) clearTmp(containers, images map[string]struct{}) { + for c := range containers { + tmp := b.builder.runtime.Get(c) + b.builder.runtime.Destroy(tmp) + utils.Debugf("Removing container %s", c) + } + for i := range images { + b.builder.runtime.graph.Delete(i) + utils.Debugf("Removing image %s", i) + } +} + +func (b *BuilderClient) From(name string) error { + obj, statusCode, err := b.cli.call("GET", "/images/"+name+"/json", nil) + if statusCode == 404 { + if err := b.cli.hijack("POST", "/images/create?fromImage="+name, false); err != nil { + return err + } + obj, _, err = b.cli.call("GET", "/images/"+name+"/json", nil) + if err != nil { + return err + } + } + if err != nil { + return err + } + + img := &ApiImages{} + if err := json.Unmarshal(obj, img); err != nil { + return err + } + b.image = img.Id + return nil +} + +func (b *BuilderClient) Maintainer(name string) error { + b.needCommit = true + b.maintainer = name + return nil +} + +func (b *BuilderClient) Run(args string) error { + if b.image == "" { + return fmt.Errorf("Please provide a source image with `from` prior to run") + } + config, _, err := ParseRun([]string{b.image, "/bin/sh", "-c", args}, b.builder.runtime.capabilities) + if err != nil { + return err + } + MergeConfig(b.config, config) + body, statusCode, err := b.cli.call("POST", "/images/getCache", &ApiImageConfig{Id: b.image, Config: b.config}) + if err != nil { + if statusCode != 404 { + return err + } + } + if statusCode != 404 { + apiId := &ApiId{} + if err := json.Unmarshal(body, apiId); err != nil { + return err + } + b.image = apiId.Id + return nil + } + + body, _, err = b.cli.call("POST", "/containers/create", b.config) + if err != nil { + return err + } + + out := &ApiRun{} + err = json.Unmarshal(body, out) + if err != nil { + return err + } + + for _, warning := range out.Warnings { + fmt.Fprintln(os.Stderr, "WARNING: ", warning) + } + + //start the container + _, _, err = b.cli.call("POST", "/containers/"+out.Id+"/start", nil) + if err != nil { + return err + } + b.tmpContainers[out.Id] = struct{}{} + + // Wait for it to finish + _, _, err = b.cli.call("POST", "/containers/"+out.Id+"/wait", nil) + if err != nil { + return err + } + + // Commit the container + v := url.Values{} + v.Set("container", out.Id) + v.Set("author", b.maintainer) + body, _, err = b.cli.call("POST", "/commit?"+v.Encode(), b.config) + if err != nil { + return err + } + apiId := &ApiId{} + err = json.Unmarshal(body, apiId) + if err != nil { + return err + } + b.tmpImages[apiId.Id] = struct{}{} + b.image = apiId.Id + b.needCommit = false + return nil +} + +func (b *BuilderClient) Env(args string) error { + b.needCommit = true + tmp := strings.SplitN(args, " ", 2) + if len(tmp) != 2 { + return fmt.Errorf("Invalid ENV format") + } + key := strings.Trim(tmp[0], " ") + value := strings.Trim(tmp[1], " ") + + for i, elem := range b.config.Env { + if strings.HasPrefix(elem, key+"=") { + b.config.Env[i] = key + "=" + value + return nil + } + } + b.config.Env = append(b.config.Env, key+"="+value) + return nil +} + +func (b *BuilderClient) Cmd(args string) error { + b.needCommit = true + b.config.Cmd = []string{"/bin/sh", "-c", args} + return nil +} + +func (b *BuilderClient) Expose(args string) error { + ports := strings.Split(args, " ") + b.config.PortSpecs = append(ports, b.config.PortSpecs...) + return nil +} + +func (b *BuilderClient) Insert(args string) error { + // FIXME: Reimplement this once the remove_hijack branch gets merged. + // We need to retrieve the resulting Id + return fmt.Errorf("INSERT not implemented") +} + +func NewBuilderClient(dockerfile io.Reader) (string, error) { + // defer b.clearTmp(tmpContainers, tmpImages) + + b := &BuilderClient{ + cli: NewDockerCli("0.0.0.0", 4243), + } + file := bufio.NewReader(dockerfile) + for { + line, err := file.ReadString('\n') + if err != nil { + if err == io.EOF { + break + } + return "", err + } + line = strings.Replace(strings.TrimSpace(line), " ", " ", 1) + // Skip comments and empty line + if len(line) == 0 || line[0] == '#' { + continue + } + tmp := strings.SplitN(line, " ", 2) + if len(tmp) != 2 { + return "", fmt.Errorf("Invalid Dockerfile format") + } + instruction := strings.ToLower(strings.Trim(tmp[0], " ")) + arguments := strings.Trim(tmp[1], " ") + + fmt.Printf("%s %s\n", strings.ToUpper(instruction), arguments) + + method, exists := reflect.TypeOf(b).MethodByName(strings.ToUpper(instruction[:1]) + strings.ToLower(instruction[1:])) + if !exists { + fmt.Printf("Skipping unknown instruction %s\n", strings.ToUpper(instruction)) + } + ret := method.Func.Call([]reflect.Value{reflect.ValueOf(b), reflect.ValueOf(arguments)})[0].Interface() + if ret != nil { + return "", ret.(error) + } + + fmt.Printf("===> %v\n", b.image) + } + if b.needCommit { + body, _, err = b.cli.call("POST", "/containers/create", b.config) + if err != nil { + return err + } + + out := &ApiRun{} + err = json.Unmarshal(body, out) + if err != nil { + return err + } + + for _, warning := range out.Warnings { + fmt.Fprintln(os.Stderr, "WARNING: ", warning) + } + + //start the container + _, _, err = b.cli.call("POST", "/containers/"+out.Id+"/start", nil) + if err != nil { + return err + } + b.tmpContainers[out.Id] = struct{}{} + + // Wait for it to finish + _, _, err = b.cli.call("POST", "/containers/"+out.Id+"/wait", nil) + if err != nil { + return err + } + + // Commit the container + v := url.Values{} + v.Set("container", out.Id) + v.Set("author", b.maintainer) + body, _, err = b.cli.call("POST", "/commit?"+v.Encode(), b.config) + if err != nil { + return err + } + apiId := &ApiId{} + err = json.Unmarshal(body, apiId) + if err != nil { + return err + } + b.tmpImages[apiId.Id] = struct{}{} + b.image = apiId.Id + } + if b.image != "" { + // The build is successful, keep the temporary containers and images + for i := range b.tmpImages { + delete(b.tmpImages, i) + } + for i := range b.tmpContainers { + delete(b.tmpContainers, i) + } + fmt.Printf("Build finished. image id: %s\n", b.image) + return b.image, nil + } + return "", fmt.Errorf("An error occured during the build\n") +} diff --git a/commands.go b/commands.go index 33ba8125d..4d63782f3 100644 --- a/commands.go +++ b/commands.go @@ -54,37 +54,37 @@ func ParseCommands(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" - for _, cmd := range [][]string{ - {"attach", "Attach to a running container"}, - {"build", "Build a container from Dockerfile via stdin"}, - {"commit", "Create a new image from a container's changes"}, - {"diff", "Inspect changes on a container's filesystem"}, - {"export", "Stream the contents of a container as a tar archive"}, - {"history", "Show the history of an image"}, - {"images", "List images"}, - {"import", "Create a new filesystem image from the contents of a tarball"}, - {"info", "Display system-wide information"}, - {"insert", "Insert a file in an image"}, - {"inspect", "Return low-level information on a container"}, - {"kill", "Kill a running container"}, - {"login", "Register or Login to the docker registry server"}, - {"logs", "Fetch the logs of a container"}, - {"port", "Lookup the public-facing port which is NAT-ed to PRIVATE_PORT"}, - {"ps", "List containers"}, - {"pull", "Pull an image or a repository from the docker registry server"}, - {"push", "Push an image or a repository to the docker registry server"}, - {"restart", "Restart a running container"}, - {"rm", "Remove a container"}, - {"rmi", "Remove an image"}, - {"run", "Run a command in a new container"}, - {"search", "Search for an image in the docker index"}, - {"start", "Start a stopped container"}, - {"stop", "Stop a running container"}, - {"tag", "Tag an image into a repository"}, - {"version", "Show the docker version information"}, - {"wait", "Block until a container stops, then print its exit code"}, + for cmd, description := range map[string]string{ + "attach": "Attach to a running container", + "build": "Build a container from Dockerfile or via stdin", + "commit": "Create a new image from a container's changes", + "diff": "Inspect changes on a container's filesystem", + "export": "Stream the contents of a container as a tar archive", + "history": "Show the history of an image", + "images": "List images", + "import": "Create a new filesystem image from the contents of a tarball", + "info": "Display system-wide information", + "insert": "Insert a file in an image", + "inspect": "Return low-level information on a container", + "kill": "Kill a running container", + "login": "Register or Login to the docker registry server", + "logs": "Fetch the logs of a container", + "port": "Lookup the public-facing port which is NAT-ed to PRIVATE_PORT", + "ps": "List containers", + "pull": "Pull an image or a repository from the docker registry server", + "push": "Push an image or a repository to the docker registry server", + "restart": "Restart a running container", + "rm": "Remove a container", + "rmi": "Remove an image", + "run": "Run a command in a new container", + "search": "Search for an image in the docker index", + "start": "Start a stopped container", + "stop": "Stop a running container", + "tag": "Tag an image into a repository", + "version": "Show the docker version information", + "wait": "Block until a container stops, then print its exit code", } { - help += fmt.Sprintf(" %-10.10s%s\n", cmd[0], cmd[1]) + help += fmt.Sprintf(" %-10.10s%s\n", cmd, description) } fmt.Println(help) return nil @@ -112,15 +112,29 @@ func (cli *DockerCli) CmdInsert(args ...string) error { } func (cli *DockerCli) CmdBuild(args ...string) error { - cmd := Subcmd("build", "-", "Build an image from Dockerfile via stdin") + cmd := Subcmd("build", "-|Dockerfile", "Build an image from Dockerfile or via stdin") if err := cmd.Parse(args); err != nil { return nil } + var ( + file io.ReadCloser + err error + ) - err := cli.hijack("POST", "/build", false) - if err != nil { - return err + if cmd.NArg() == 0 { + file, err = os.Open("Dockerfile") + if err != nil { + return err + } + } else if cmd.Arg(0) == "-" { + file = os.Stdin + } else { + file, err = os.Open(cmd.Arg(0)) + if err != nil { + return err + } } + NewBuilderClient(file) return nil } diff --git a/server.go b/server.go index dafa44ec8..9877b1efd 100644 --- a/server.go +++ b/server.go @@ -140,8 +140,10 @@ func (srv *Server) ImagesViz(out io.Writer) error { } func (srv *Server) Images(all bool, filter string) ([]ApiImages, error) { - var allImages map[string]*Image - var err error + var ( + allImages map[string]*Image + err error + ) if all { allImages, err = srv.runtime.graph.Map() } else { @@ -150,7 +152,7 @@ func (srv *Server) Images(all bool, filter string) ([]ApiImages, error) { if err != nil { return nil, err } - var outs []ApiImages = []ApiImages{} //produce [] when empty instead of 'null' + outs := []ApiImages{} //produce [] when empty instead of 'null' for name, repository := range srv.runtime.repositories.Repositories { if filter != "" && name != filter { continue @@ -653,15 +655,6 @@ func (srv *Server) ContainerCreate(config *Config) (string, error) { return container.ShortId(), nil } -func (srv *Server) ImageCreateFromFile(dockerfile io.Reader, out io.Writer) error { - img, err := NewBuilder(srv.runtime).Build(dockerfile, out) - if err != nil { - return err - } - fmt.Fprintf(out, "%s\n", img.ShortId()) - return nil -} - func (srv *Server) ContainerRestart(name string, t int) error { if container := srv.runtime.Get(name); container != nil { if err := container.Restart(t); err != nil { @@ -722,6 +715,36 @@ func (srv *Server) ImageDelete(name string) error { return nil } +func (srv *Server) ImageGetCached(imgId string, config *Config) (*Image, error) { + + // Retrieve all images + images, err := srv.runtime.graph.All() + if err != nil { + return nil, err + } + + // Store the tree in a map of map (map[parentId][childId]) + imageMap := make(map[string]map[string]struct{}) + for _, img := range images { + if _, exists := imageMap[img.Parent]; !exists { + imageMap[img.Parent] = make(map[string]struct{}) + } + imageMap[img.Parent][img.Id] = struct{}{} + } + + // Loop on the children of the given image and check the config + for elem := range imageMap[imgId] { + img, err := srv.runtime.graph.Get(elem) + if err != nil { + return nil, err + } + if CompareConfig(&img.ContainerConfig, config) { + return img, nil + } + } + return nil, nil +} + func (srv *Server) ContainerStart(name string) error { if container := srv.runtime.Get(name); container != nil { if err := container.Start(); err != nil { diff --git a/utils.go b/utils.go index d67f50e52..27478002d 100644 --- a/utils.go +++ b/utils.go @@ -47,3 +47,42 @@ func CompareConfig(a, b *Config) bool { return true } + +func MergeConfig(userConf, imageConf *Config) { + if userConf.Hostname != "" { + userConf.Hostname = imageConf.Hostname + } + if userConf.User != "" { + userConf.User = imageConf.User + } + if userConf.Memory == 0 { + userConf.Memory = imageConf.Memory + } + if userConf.MemorySwap == 0 { + userConf.MemorySwap = imageConf.MemorySwap + } + if userConf.CpuShares == 0 { + userConf.CpuShares = imageConf.CpuShares + } + if userConf.PortSpecs == nil || len(userConf.PortSpecs) == 0 { + userConf.PortSpecs = imageConf.PortSpecs + } + if !userConf.Tty { + userConf.Tty = imageConf.Tty + } + if !userConf.OpenStdin { + userConf.OpenStdin = imageConf.OpenStdin + } + if !userConf.StdinOnce { + userConf.StdinOnce = imageConf.StdinOnce + } + if userConf.Env == nil || len(userConf.Env) == 0 { + userConf.Env = imageConf.Env + } + if userConf.Cmd == nil || len(userConf.Cmd) == 0 { + userConf.Cmd = imageConf.Cmd + } + if userConf.Dns == nil || len(userConf.Dns) == 0 { + userConf.Dns = imageConf.Dns + } +} From 98b0fd173b7b59316d776534b84ecc9ab0a1da77 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Mon, 20 May 2013 10:22:50 -0700 Subject: [PATCH 16/95] Make the printflfush an interface --- server.go | 42 ++++++++++++++++++++++++------------------ utils/utils.go | 19 +++++++++++-------- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/server.go b/server.go index 6576fac0d..b07e85b44 100644 --- a/server.go +++ b/server.go @@ -68,6 +68,7 @@ func (srv *Server) ImagesSearch(term string) ([]ApiSearch, error) { } func (srv *Server) ImageInsert(name, url, path string, out io.Writer) error { + out = &utils.WriteFlusher{W: out} img, err := srv.runtime.repositories.LookupImage(name) if err != nil { return err @@ -98,7 +99,7 @@ func (srv *Server) ImageInsert(name, url, path string, out io.Writer) error { if err != nil { return err } - utils.FprintfFlush(out, "%s\n", img.Id) + fmt.Fprintf(out, "%s\n", img.Id) return nil } @@ -289,6 +290,7 @@ func (srv *Server) ContainerTag(name, repo, tag string, force bool) error { } func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []string) error { + out = &utils.WriteFlusher{W: out} history, err := srv.registry.GetRemoteHistory(imgId, registry, token) if err != nil { return err @@ -298,7 +300,7 @@ func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []stri // FIXME: Launch the getRemoteImage() in goroutines for _, id := range history { if !srv.runtime.graph.Exists(id) { - utils.FprintfFlush(out, "Pulling %s metadata\r\n", id) + fmt.Fprintf(out, "Pulling %s metadata\r\n", id) imgJson, err := srv.registry.GetRemoteImageJson(id, registry, token) if err != nil { // FIXME: Keep goging in case of error? @@ -310,7 +312,7 @@ func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []stri } // Get the layer - utils.FprintfFlush(out, "Pulling %s fs layer\r\n", img.Id) + fmt.Fprintf(out, "Pulling %s fs layer\r\n", img.Id) layer, contentLength, err := srv.registry.GetRemoteImageLayer(img.Id, registry, token) if err != nil { return err @@ -324,7 +326,8 @@ func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []stri } func (srv *Server) pullRepository(out io.Writer, remote, askedTag string) error { - utils.FprintfFlush(out, "Pulling repository %s from %s\r\n", remote, auth.IndexServerAddress()) + out = &utils.WriteFlusher{W: out} + fmt.Fprintf(out, "Pulling repository %s from %s\r\n", remote, auth.IndexServerAddress()) repoData, err := srv.registry.GetRepositoryData(remote) if err != nil { return err @@ -350,11 +353,11 @@ func (srv *Server) pullRepository(out io.Writer, remote, askedTag string) error if askedTag != "" && askedTag != img.Tag { continue } - utils.FprintfFlush(out, "Pulling image %s (%s) from %s\n", img.Id, img.Tag, remote) + fmt.Fprintf(out, "Pulling image %s (%s) from %s\n", img.Id, img.Tag, remote) success := false for _, ep := range repoData.Endpoints { if err := srv.pullImage(out, img.Id, "https://"+ep+"/v1", repoData.Tokens); err != nil { - utils.FprintfFlush(out, "Error while retrieving image for tag: %s (%s); checking next endpoint\n", askedTag, err) + fmt.Fprintf(out, "Error while retrieving image for tag: %s (%s); checking next endpoint\n", askedTag, err) continue } if err := srv.runtime.repositories.Set(remote, img.Tag, img.Id, true); err != nil { @@ -462,12 +465,13 @@ func (srv *Server) getImageList(localRepo map[string]string) ([]*registry.ImgDat } func (srv *Server) pushRepository(out io.Writer, name string, localRepo map[string]string) error { - utils.FprintfFlush(out, "Processing checksums\n") + out = &utils.WriteFlusher{W: out} + fmt.Fprintf(out, "Processing checksums\n") imgList, err := srv.getImageList(localRepo) if err != nil { return err } - utils.FprintfFlush(out, "Sending image list\n") + fmt.Fprintf(out, "Sending image list\n") repoData, err := srv.registry.PushImageJsonIndex(name, imgList, false) if err != nil { @@ -476,18 +480,18 @@ func (srv *Server) pushRepository(out io.Writer, name string, localRepo map[stri // FIXME: Send only needed images for _, ep := range repoData.Endpoints { - utils.FprintfFlush(out, "Pushing repository %s to %s (%d tags)\r\n", name, ep, len(localRepo)) + fmt.Fprintf(out, "Pushing repository %s to %s (%d tags)\r\n", name, ep, len(localRepo)) // For each image within the repo, push them for _, elem := range imgList { if _, exists := repoData.ImgList[elem.Id]; exists { - utils.FprintfFlush(out, "Image %s already on registry, skipping\n", name) + fmt.Fprintf(out, "Image %s already on registry, skipping\n", name) continue } if err := srv.pushImage(out, name, elem.Id, ep, repoData.Tokens); err != nil { // FIXME: Continue on error? return err } - utils.FprintfFlush(out, "Pushing tags for rev [%s] on {%s}\n", elem.Id, ep+"/users/"+name+"/"+elem.Tag) + fmt.Fprintf(out, "Pushing tags for rev [%s] on {%s}\n", elem.Id, ep+"/users/"+name+"/"+elem.Tag) if err := srv.registry.PushRegistryTag(name, elem.Id, elem.Tag, ep, repoData.Tokens); err != nil { return err } @@ -501,11 +505,12 @@ func (srv *Server) pushRepository(out io.Writer, name string, localRepo map[stri } func (srv *Server) pushImage(out io.Writer, remote, imgId, ep string, token []string) error { + out = &utils.WriteFlusher{W: out} jsonRaw, err := ioutil.ReadFile(path.Join(srv.runtime.graph.Root, imgId, "json")) if err != nil { return fmt.Errorf("Error while retreiving the path for {%s}: %s", imgId, err) } - utils.FprintfFlush(out, "Pushing %s\r\n", imgId) + fmt.Fprintf(out, "Pushing %s\r\n", imgId) // Make sure we have the image's checksum checksum, err := srv.getChecksum(imgId) @@ -520,7 +525,7 @@ func (srv *Server) pushImage(out io.Writer, remote, imgId, ep string, token []st // Send the json if err := srv.registry.PushImageJsonRegistry(imgData, jsonRaw, ep, token); err != nil { if err == registry.ErrAlreadyExists { - utils.FprintfFlush(out, "Image %s already uploaded ; skipping\n", imgData.Id) + fmt.Fprintf(out, "Image %s already uploaded ; skipping\n", imgData.Id) return nil } return err @@ -560,9 +565,10 @@ func (srv *Server) pushImage(out io.Writer, remote, imgId, ep string, token []st } func (srv *Server) ImagePush(name, registry string, out io.Writer) error { + out = &utils.WriteFlusher{W: out} img, err := srv.runtime.graph.Get(name) if err != nil { - utils.FprintfFlush(out, "The push refers to a repository [%s] (len: %d)\n", name, len(srv.runtime.repositories.Repositories[name])) + fmt.Fprintf(out, "The push refers to a repository [%s] (len: %d)\n", name, len(srv.runtime.repositories.Repositories[name])) // If it fails, try to get the repository if localRepo, exists := srv.runtime.repositories.Repositories[name]; exists { if err := srv.pushRepository(out, name, localRepo); err != nil { @@ -573,7 +579,7 @@ func (srv *Server) ImagePush(name, registry string, out io.Writer) error { return err } - utils.FprintfFlush(out, "The push refers to an image: [%s]\n", name) + fmt.Fprintf(out, "The push refers to an image: [%s]\n", name) if err := srv.pushImage(out, name, img.Id, registry, nil); err != nil { return err } @@ -589,14 +595,14 @@ func (srv *Server) ImageImport(src, repo, tag string, in io.Reader, out io.Write } else { u, err := url.Parse(src) if err != nil { - utils.FprintfFlush(out, "Error: %s\n", err) + fmt.Fprintf(out, "Error: %s\n", err) } if u.Scheme == "" { u.Scheme = "http" u.Host = src u.Path = "" } - utils.FprintfFlush(out, "Downloading from %s\n", u) + fmt.Fprintf(out, "Downloading from %s\n", u) // Download with curl (pretty progress bar) // If curl is not available, fallback to http.Get() resp, err = utils.Download(u.String(), out) @@ -615,7 +621,7 @@ func (srv *Server) ImageImport(src, repo, tag string, in io.Reader, out io.Write return err } } - utils.FprintfFlush(out, "%s\n", img.ShortId()) + fmt.Fprintf(out, "%s\n", img.ShortId()) return nil } diff --git a/utils/utils.go b/utils/utils.go index 6a6a9f95b..a2fd3bde6 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -84,15 +84,15 @@ func (r *progressReader) Read(p []byte) (n int, err error) { } if r.readProgress-r.lastUpdate > updateEvery || err != nil { if r.readTotal > 0 { - FprintfFlush(r.output, r.template+"\r", r.readProgress, r.readTotal, fmt.Sprintf("%.0f%%", float64(r.readProgress)/float64(r.readTotal)*100)) + fmt.Fprintf(r.output, r.template+"\r", r.readProgress, r.readTotal, fmt.Sprintf("%.0f%%", float64(r.readProgress)/float64(r.readTotal)*100)) } else { - FprintfFlush(r.output, r.template+"\r", r.readProgress, "?", "n/a") + fmt.Fprintf(r.output, r.template+"\r", r.readProgress, "?", "n/a") } r.lastUpdate = r.readProgress } // Send newline when complete if err != nil { - FprintfFlush(r.output, "\n") + fmt.Fprintf(r.output, "\n") } return read, err @@ -104,7 +104,7 @@ func ProgressReader(r io.ReadCloser, size int, output io.Writer, template string if template == "" { template = "%v/%v (%v)" } - return &progressReader{r, output, size, 0, 0, template} + return &progressReader{r, &WriteFlusher{W: output}, size, 0, 0, template} } // HumanDuration returns a human-readable approximation of a duration @@ -531,11 +531,14 @@ func GetKernelVersion() (*KernelVersionInfo, error) { }, nil } +type WriteFlusher struct { + W io.Writer +} -func FprintfFlush(w io.Writer, format string, a ...interface{}) (n int, err error) { - n, err = fmt.Fprintf(w, format, a...) - if f, ok := w.(http.Flusher); ok { +func (wf *WriteFlusher) Write(b []byte) (n int, err error) { + n, err = wf.W.Write(b) + if f, ok := wf.W.(http.Flusher); ok { f.Flush() } return n, err -} \ No newline at end of file +} From 1b007828c93bc472af3306b8da1d72a84b484f12 Mon Sep 17 00:00:00 2001 From: unclejack Date: Mon, 20 May 2013 20:43:09 +0300 Subject: [PATCH 17/95] fix compilation on linux --- utils/uname_linux.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/uname_linux.go b/utils/uname_linux.go index 6e47bcc82..063f932c9 100644 --- a/utils/uname_linux.go +++ b/utils/uname_linux.go @@ -6,7 +6,7 @@ import ( type Utsname syscall.Utsname -func uname() (*Utsname, error) { +func uname() (*syscall.Utsname, error) { uts := &syscall.Utsname{} if err := syscall.Uname(uts); err != nil { From ae9d7a5167da58de9a1a4beac489cf1e6adcea11 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Mon, 20 May 2013 10:58:35 -0700 Subject: [PATCH 18/95] Avoid cast each write for flusher --- server.go | 12 ++++++------ utils/utils.go | 25 +++++++++++++++++++------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/server.go b/server.go index b07e85b44..956a4f8d3 100644 --- a/server.go +++ b/server.go @@ -68,7 +68,7 @@ func (srv *Server) ImagesSearch(term string) ([]ApiSearch, error) { } func (srv *Server) ImageInsert(name, url, path string, out io.Writer) error { - out = &utils.WriteFlusher{W: out} + out = utils.NewWriteFlusher(out) img, err := srv.runtime.repositories.LookupImage(name) if err != nil { return err @@ -290,7 +290,7 @@ func (srv *Server) ContainerTag(name, repo, tag string, force bool) error { } func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []string) error { - out = &utils.WriteFlusher{W: out} + out = utils.NewWriteFlusher(out) history, err := srv.registry.GetRemoteHistory(imgId, registry, token) if err != nil { return err @@ -326,7 +326,7 @@ func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []stri } func (srv *Server) pullRepository(out io.Writer, remote, askedTag string) error { - out = &utils.WriteFlusher{W: out} + out = utils.NewWriteFlusher(out) fmt.Fprintf(out, "Pulling repository %s from %s\r\n", remote, auth.IndexServerAddress()) repoData, err := srv.registry.GetRepositoryData(remote) if err != nil { @@ -465,7 +465,7 @@ func (srv *Server) getImageList(localRepo map[string]string) ([]*registry.ImgDat } func (srv *Server) pushRepository(out io.Writer, name string, localRepo map[string]string) error { - out = &utils.WriteFlusher{W: out} + out = utils.NewWriteFlusher(out) fmt.Fprintf(out, "Processing checksums\n") imgList, err := srv.getImageList(localRepo) if err != nil { @@ -505,7 +505,7 @@ func (srv *Server) pushRepository(out io.Writer, name string, localRepo map[stri } func (srv *Server) pushImage(out io.Writer, remote, imgId, ep string, token []string) error { - out = &utils.WriteFlusher{W: out} + out = utils.NewWriteFlusher(out) jsonRaw, err := ioutil.ReadFile(path.Join(srv.runtime.graph.Root, imgId, "json")) if err != nil { return fmt.Errorf("Error while retreiving the path for {%s}: %s", imgId, err) @@ -565,7 +565,7 @@ func (srv *Server) pushImage(out io.Writer, remote, imgId, ep string, token []st } func (srv *Server) ImagePush(name, registry string, out io.Writer) error { - out = &utils.WriteFlusher{W: out} + out = utils.NewWriteFlusher(out) img, err := srv.runtime.graph.Get(name) if err != nil { fmt.Fprintf(out, "The push refers to a repository [%s] (len: %d)\n", name, len(srv.runtime.repositories.Repositories[name])) diff --git a/utils/utils.go b/utils/utils.go index a2fd3bde6..150eae857 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -104,7 +104,7 @@ func ProgressReader(r io.ReadCloser, size int, output io.Writer, template string if template == "" { template = "%v/%v (%v)" } - return &progressReader{r, &WriteFlusher{W: output}, size, 0, 0, template} + return &progressReader{r, NewWriteFlusher(output), size, 0, 0, template} } // HumanDuration returns a human-readable approximation of a duration @@ -531,14 +531,27 @@ func GetKernelVersion() (*KernelVersionInfo, error) { }, nil } +type NopFlusher struct{} + +func (f *NopFlusher) Flush() {} + type WriteFlusher struct { - W io.Writer + w io.Writer + flusher http.Flusher } func (wf *WriteFlusher) Write(b []byte) (n int, err error) { - n, err = wf.W.Write(b) - if f, ok := wf.W.(http.Flusher); ok { - f.Flush() - } + n, err = wf.w.Write(b) + wf.flusher.Flush() return n, err } + +func NewWriteFlusher(w io.Writer) *WriteFlusher { + var flusher http.Flusher + if f, ok := w.(http.Flusher); ok { + flusher = f + } else { + flusher = &NopFlusher{} + } + return &WriteFlusher{w: w, flusher: flusher} +} From c2a14bb196d0d3046e185783ebacd4b83fa36dd4 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Mon, 20 May 2013 12:09:15 -0700 Subject: [PATCH 19/95] Add "Cmd" prefix to builder instructions --- api.go | 4 ++ builder_client.go | 164 +++++++++++++++++++--------------------------- commands.go | 4 +- 3 files changed, 73 insertions(+), 99 deletions(-) diff --git a/api.go b/api.go index 5cb3da85c..ecad0b1f4 100644 --- a/api.go +++ b/api.go @@ -590,6 +590,10 @@ func postImagesGetCache(srv *Server, w http.ResponseWriter, r *http.Request, var if err != nil { return err } + if image == nil { + w.WriteHeader(http.StatusNotFound) + return nil + } apiId := &ApiId{Id: image.Id} b, err := json.Marshal(apiId) if err != nil { diff --git a/builder_client.go b/builder_client.go index 4a29129ed..0ad35045d 100644 --- a/builder_client.go +++ b/builder_client.go @@ -13,8 +13,7 @@ import ( ) type BuilderClient struct { - builder *Builder - cli *DockerCli + cli *DockerCli image string maintainer string @@ -28,17 +27,20 @@ type BuilderClient struct { func (b *BuilderClient) clearTmp(containers, images map[string]struct{}) { for c := range containers { - tmp := b.builder.runtime.Get(c) - b.builder.runtime.Destroy(tmp) + if _, _, err := b.cli.call("DELETE", "/containers/"+c, nil); err != nil { + utils.Debugf("%s", err) + } utils.Debugf("Removing container %s", c) } for i := range images { - b.builder.runtime.graph.Delete(i) + if _, _, err := b.cli.call("DELETE", "/images/"+i, nil); err != nil { + utils.Debugf("%s", err) + } utils.Debugf("Removing image %s", i) } } -func (b *BuilderClient) From(name string) error { +func (b *BuilderClient) CmdFrom(name string) error { obj, statusCode, err := b.cli.call("GET", "/images/"+name+"/json", nil) if statusCode == 404 { if err := b.cli.hijack("POST", "/images/create?fromImage="+name, false); err != nil { @@ -53,7 +55,7 @@ func (b *BuilderClient) From(name string) error { return err } - img := &ApiImages{} + img := &ApiId{} if err := json.Unmarshal(obj, img); err != nil { return err } @@ -61,17 +63,17 @@ func (b *BuilderClient) From(name string) error { return nil } -func (b *BuilderClient) Maintainer(name string) error { +func (b *BuilderClient) CmdMaintainer(name string) error { b.needCommit = true b.maintainer = name return nil } -func (b *BuilderClient) Run(args string) error { +func (b *BuilderClient) CmdRun(args string) error { if b.image == "" { return fmt.Errorf("Please provide a source image with `from` prior to run") } - config, _, err := ParseRun([]string{b.image, "/bin/sh", "-c", args}, b.builder.runtime.capabilities) + config, _, err := ParseRun([]string{b.image, "/bin/sh", "-c", args}, nil) if err != nil { return err } @@ -90,8 +92,49 @@ func (b *BuilderClient) Run(args string) error { b.image = apiId.Id return nil } + b.commit() + return nil +} - body, _, err = b.cli.call("POST", "/containers/create", b.config) +func (b *BuilderClient) CmdEnv(args string) error { + b.needCommit = true + tmp := strings.SplitN(args, " ", 2) + if len(tmp) != 2 { + return fmt.Errorf("Invalid ENV format") + } + key := strings.Trim(tmp[0], " ") + value := strings.Trim(tmp[1], " ") + + for i, elem := range b.config.Env { + if strings.HasPrefix(elem, key+"=") { + b.config.Env[i] = key + "=" + value + return nil + } + } + b.config.Env = append(b.config.Env, key+"="+value) + return nil +} + +func (b *BuilderClient) CmdCmd(args string) error { + b.needCommit = true + b.config.Cmd = []string{"/bin/sh", "-c", args} + return nil +} + +func (b *BuilderClient) CmdExpose(args string) error { + ports := strings.Split(args, " ") + b.config.PortSpecs = append(ports, b.config.PortSpecs...) + return nil +} + +func (b *BuilderClient) CmdInsert(args string) error { + // FIXME: Reimplement this once the remove_hijack branch gets merged. + // We need to retrieve the resulting Id + return fmt.Errorf("INSERT not implemented") +} + +func (b *BuilderClient) commit() error { + body, _, err := b.cli.call("POST", "/containers/create", b.config) if err != nil { return err } @@ -134,53 +177,11 @@ func (b *BuilderClient) Run(args string) error { } b.tmpImages[apiId.Id] = struct{}{} b.image = apiId.Id - b.needCommit = false return nil } -func (b *BuilderClient) Env(args string) error { - b.needCommit = true - tmp := strings.SplitN(args, " ", 2) - if len(tmp) != 2 { - return fmt.Errorf("Invalid ENV format") - } - key := strings.Trim(tmp[0], " ") - value := strings.Trim(tmp[1], " ") - - for i, elem := range b.config.Env { - if strings.HasPrefix(elem, key+"=") { - b.config.Env[i] = key + "=" + value - return nil - } - } - b.config.Env = append(b.config.Env, key+"="+value) - return nil -} - -func (b *BuilderClient) Cmd(args string) error { - b.needCommit = true - b.config.Cmd = []string{"/bin/sh", "-c", args} - return nil -} - -func (b *BuilderClient) Expose(args string) error { - ports := strings.Split(args, " ") - b.config.PortSpecs = append(ports, b.config.PortSpecs...) - return nil -} - -func (b *BuilderClient) Insert(args string) error { - // FIXME: Reimplement this once the remove_hijack branch gets merged. - // We need to retrieve the resulting Id - return fmt.Errorf("INSERT not implemented") -} - -func NewBuilderClient(dockerfile io.Reader) (string, error) { +func (b *BuilderClient) Build(dockerfile io.Reader) (string, error) { // defer b.clearTmp(tmpContainers, tmpImages) - - b := &BuilderClient{ - cli: NewDockerCli("0.0.0.0", 4243), - } file := bufio.NewReader(dockerfile) for { line, err := file.ReadString('\n') @@ -204,7 +205,7 @@ func NewBuilderClient(dockerfile io.Reader) (string, error) { fmt.Printf("%s %s\n", strings.ToUpper(instruction), arguments) - method, exists := reflect.TypeOf(b).MethodByName(strings.ToUpper(instruction[:1]) + strings.ToLower(instruction[1:])) + method, exists := reflect.TypeOf(b).MethodByName("Cmd" + strings.ToUpper(instruction[:1]) + strings.ToLower(instruction[1:])) if !exists { fmt.Printf("Skipping unknown instruction %s\n", strings.ToUpper(instruction)) } @@ -216,49 +217,7 @@ func NewBuilderClient(dockerfile io.Reader) (string, error) { fmt.Printf("===> %v\n", b.image) } if b.needCommit { - body, _, err = b.cli.call("POST", "/containers/create", b.config) - if err != nil { - return err - } - - out := &ApiRun{} - err = json.Unmarshal(body, out) - if err != nil { - return err - } - - for _, warning := range out.Warnings { - fmt.Fprintln(os.Stderr, "WARNING: ", warning) - } - - //start the container - _, _, err = b.cli.call("POST", "/containers/"+out.Id+"/start", nil) - if err != nil { - return err - } - b.tmpContainers[out.Id] = struct{}{} - - // Wait for it to finish - _, _, err = b.cli.call("POST", "/containers/"+out.Id+"/wait", nil) - if err != nil { - return err - } - - // Commit the container - v := url.Values{} - v.Set("container", out.Id) - v.Set("author", b.maintainer) - body, _, err = b.cli.call("POST", "/commit?"+v.Encode(), b.config) - if err != nil { - return err - } - apiId := &ApiId{} - err = json.Unmarshal(body, apiId) - if err != nil { - return err - } - b.tmpImages[apiId.Id] = struct{}{} - b.image = apiId.Id + b.commit() } if b.image != "" { // The build is successful, keep the temporary containers and images @@ -273,3 +232,12 @@ func NewBuilderClient(dockerfile io.Reader) (string, error) { } return "", fmt.Errorf("An error occured during the build\n") } + +func NewBuilderClient(addr string, port int) *BuilderClient { + return &BuilderClient{ + cli: NewDockerCli(addr, port), + config: &Config{}, + tmpContainers: make(map[string]struct{}), + tmpImages: make(map[string]struct{}), + } +} diff --git a/commands.go b/commands.go index 4d63782f3..8da400abe 100644 --- a/commands.go +++ b/commands.go @@ -134,7 +134,9 @@ func (cli *DockerCli) CmdBuild(args ...string) error { return err } } - NewBuilderClient(file) + if _, err := NewBuilderClient("0.0.0.0", 4243).Build(file); err != nil { + return err + } return nil } From b51303cddce2cbb22fc3ee0de9d9125bec2f029a Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Mon, 20 May 2013 13:50:50 -0700 Subject: [PATCH 20/95] Make sure to have a command to execute upon commit --- builder_client.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/builder_client.go b/builder_client.go index 0ad35045d..0c7ea15e1 100644 --- a/builder_client.go +++ b/builder_client.go @@ -134,6 +134,10 @@ func (b *BuilderClient) CmdInsert(args string) error { } func (b *BuilderClient) commit() error { + if b.config.Cmd == nil || len(b.config.Cmd) < 1 { + b.config.Cmd = []string{"echo"} + } + body, _, err := b.cli.call("POST", "/containers/create", b.config) if err != nil { return err From c6bc90d02daa2f7086a1c7469c7239911c2bc357 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Mon, 20 May 2013 15:02:32 -0700 Subject: [PATCH 21/95] Isolate run() from commit --- builder_client.go | 83 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 60 insertions(+), 23 deletions(-) diff --git a/builder_client.go b/builder_client.go index 0c7ea15e1..660ef12f8 100644 --- a/builder_client.go +++ b/builder_client.go @@ -77,7 +77,11 @@ func (b *BuilderClient) CmdRun(args string) error { if err != nil { return err } + + cmd, env := b.config.Cmd, b.config.Env + b.config.Cmd = nil MergeConfig(b.config, config) + body, statusCode, err := b.cli.call("POST", "/images/getCache", &ApiImageConfig{Id: b.image, Config: b.config}) if err != nil { if statusCode != 404 { @@ -89,11 +93,16 @@ func (b *BuilderClient) CmdRun(args string) error { if err := json.Unmarshal(body, apiId); err != nil { return err } + utils.Debugf("Use cached version") b.image = apiId.Id return nil } - b.commit() - return nil + cid, err := b.run() + if err != nil { + return err + } + b.config.Cmd, b.config.Env = cmd, env + return b.commit(cid) } func (b *BuilderClient) CmdEnv(args string) error { @@ -133,54 +142,80 @@ func (b *BuilderClient) CmdInsert(args string) error { return fmt.Errorf("INSERT not implemented") } -func (b *BuilderClient) commit() error { - if b.config.Cmd == nil || len(b.config.Cmd) < 1 { - b.config.Cmd = []string{"echo"} +func (b *BuilderClient) run() (string, error) { + if b.image == "" { + return "", fmt.Errorf("Please provide a source image with `from` prior to run") } - + b.config.Image = b.image body, _, err := b.cli.call("POST", "/containers/create", b.config) if err != nil { - return err + return "", err } - out := &ApiRun{} - err = json.Unmarshal(body, out) - if err != nil { - return err + apiRun := &ApiRun{} + if err := json.Unmarshal(body, apiRun); err != nil { + return "", err } - - for _, warning := range out.Warnings { + for _, warning := range apiRun.Warnings { fmt.Fprintln(os.Stderr, "WARNING: ", warning) } //start the container - _, _, err = b.cli.call("POST", "/containers/"+out.Id+"/start", nil) + _, _, err = b.cli.call("POST", "/containers/"+apiRun.Id+"/start", nil) if err != nil { - return err + return "", err } - b.tmpContainers[out.Id] = struct{}{} + b.tmpContainers[apiRun.Id] = struct{}{} // Wait for it to finish - _, _, err = b.cli.call("POST", "/containers/"+out.Id+"/wait", nil) + body, _, err = b.cli.call("POST", "/containers/"+apiRun.Id+"/wait", nil) if err != nil { - return err + return "", err + } + apiWait := &ApiWait{} + if err := json.Unmarshal(body, apiWait); err != nil { + return "", err + } + if apiWait.StatusCode != 0 { + return "", fmt.Errorf("The command %v returned a non-zero code: %d", b.config.Cmd, apiWait.StatusCode) + } + + return apiRun.Id, nil +} + +func (b *BuilderClient) commit(id string) error { + if b.image == "" { + return fmt.Errorf("Please provide a source image with `from` prior to run") + } + b.config.Image = b.image + + if id == "" { + cmd := b.config.Cmd + b.config.Cmd = []string{"true"} + if cid, err := b.run(); err != nil { + return err + } else { + id = cid + } + b.config.Cmd = cmd } // Commit the container v := url.Values{} - v.Set("container", out.Id) + v.Set("container", id) v.Set("author", b.maintainer) - body, _, err = b.cli.call("POST", "/commit?"+v.Encode(), b.config) + + body, _, err := b.cli.call("POST", "/commit?"+v.Encode(), b.config) if err != nil { return err } apiId := &ApiId{} - err = json.Unmarshal(body, apiId) - if err != nil { + if err := json.Unmarshal(body, apiId); err != nil { return err } b.tmpImages[apiId.Id] = struct{}{} b.image = apiId.Id + b.needCommit = false return nil } @@ -221,7 +256,9 @@ func (b *BuilderClient) Build(dockerfile io.Reader) (string, error) { fmt.Printf("===> %v\n", b.image) } if b.needCommit { - b.commit() + if err := b.commit(""); err != nil { + return "", err + } } if b.image != "" { // The build is successful, keep the temporary containers and images From d756ae4cb376e218ff4dd35a7b9a9fa346fbb04d Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Mon, 20 May 2013 15:19:05 -0700 Subject: [PATCH 22/95] Tag all images after pulling them --- server.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/server.go b/server.go index d33624827..3f27a178c 100644 --- a/server.go +++ b/server.go @@ -371,11 +371,7 @@ func (srv *Server) pullRepository(out io.Writer, remote, askedTag string) error fmt.Fprintf(out, "Error while retrieving image for tag: %s (%s); checking next endpoint\n", askedTag, err) continue } - if err := srv.runtime.repositories.Set(remote, img.Tag, img.Id, true); err != nil { - return err - } success = true - delete(tagsList, img.Tag) break } if !success { From b06784b0dd2e86a7450fab30707468acfae5d7aa Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Mon, 20 May 2013 16:00:16 -0700 Subject: [PATCH 23/95] Make docker client an interface --- builder_client.go | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/builder_client.go b/builder_client.go index 660ef12f8..5000782f8 100644 --- a/builder_client.go +++ b/builder_client.go @@ -12,7 +12,13 @@ import ( "strings" ) -type BuilderClient struct { +type BuilderClient interface { + Build(io.Reader) (string, error) + CmdFrom(string) error + CmdRun(string) error +} + +type builderClient struct { cli *DockerCli image string @@ -25,7 +31,7 @@ type BuilderClient struct { needCommit bool } -func (b *BuilderClient) clearTmp(containers, images map[string]struct{}) { +func (b builderClient) clearTmp(containers, images map[string]struct{}) { for c := range containers { if _, _, err := b.cli.call("DELETE", "/containers/"+c, nil); err != nil { utils.Debugf("%s", err) @@ -40,7 +46,7 @@ func (b *BuilderClient) clearTmp(containers, images map[string]struct{}) { } } -func (b *BuilderClient) CmdFrom(name string) error { +func (b builderClient) CmdFrom(name string) error { obj, statusCode, err := b.cli.call("GET", "/images/"+name+"/json", nil) if statusCode == 404 { if err := b.cli.hijack("POST", "/images/create?fromImage="+name, false); err != nil { @@ -63,13 +69,13 @@ func (b *BuilderClient) CmdFrom(name string) error { return nil } -func (b *BuilderClient) CmdMaintainer(name string) error { +func (b builderClient) CmdMaintainer(name string) error { b.needCommit = true b.maintainer = name return nil } -func (b *BuilderClient) CmdRun(args string) error { +func (b builderClient) CmdRun(args string) error { if b.image == "" { return fmt.Errorf("Please provide a source image with `from` prior to run") } @@ -105,7 +111,7 @@ func (b *BuilderClient) CmdRun(args string) error { return b.commit(cid) } -func (b *BuilderClient) CmdEnv(args string) error { +func (b builderClient) CmdEnv(args string) error { b.needCommit = true tmp := strings.SplitN(args, " ", 2) if len(tmp) != 2 { @@ -124,25 +130,25 @@ func (b *BuilderClient) CmdEnv(args string) error { return nil } -func (b *BuilderClient) CmdCmd(args string) error { +func (b builderClient) CmdCmd(args string) error { b.needCommit = true b.config.Cmd = []string{"/bin/sh", "-c", args} return nil } -func (b *BuilderClient) CmdExpose(args string) error { +func (b builderClient) CmdExpose(args string) error { ports := strings.Split(args, " ") b.config.PortSpecs = append(ports, b.config.PortSpecs...) return nil } -func (b *BuilderClient) CmdInsert(args string) error { +func (b builderClient) CmdInsert(args string) error { // FIXME: Reimplement this once the remove_hijack branch gets merged. // We need to retrieve the resulting Id return fmt.Errorf("INSERT not implemented") } -func (b *BuilderClient) run() (string, error) { +func (b builderClient) run() (string, error) { if b.image == "" { return "", fmt.Errorf("Please provide a source image with `from` prior to run") } @@ -183,7 +189,7 @@ func (b *BuilderClient) run() (string, error) { return apiRun.Id, nil } -func (b *BuilderClient) commit(id string) error { +func (b builderClient) commit(id string) error { if b.image == "" { return fmt.Errorf("Please provide a source image with `from` prior to run") } @@ -219,7 +225,7 @@ func (b *BuilderClient) commit(id string) error { return nil } -func (b *BuilderClient) Build(dockerfile io.Reader) (string, error) { +func (b builderClient) Build(dockerfile io.Reader) (string, error) { // defer b.clearTmp(tmpContainers, tmpImages) file := bufio.NewReader(dockerfile) for { @@ -274,8 +280,8 @@ func (b *BuilderClient) Build(dockerfile io.Reader) (string, error) { return "", fmt.Errorf("An error occured during the build\n") } -func NewBuilderClient(addr string, port int) *BuilderClient { - return &BuilderClient{ +func NewBuilderClient(addr string, port int) BuilderClient { + return &builderClient{ cli: NewDockerCli(addr, port), config: &Config{}, tmpContainers: make(map[string]struct{}), From 13e687e5790f05552f9be84bf1d60d37fca4c078 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Mon, 20 May 2013 16:00:51 -0700 Subject: [PATCH 24/95] Allow multiple syntaxes for CMD --- builder_client.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/builder_client.go b/builder_client.go index 5000782f8..0c283d259 100644 --- a/builder_client.go +++ b/builder_client.go @@ -132,7 +132,12 @@ func (b builderClient) CmdEnv(args string) error { func (b builderClient) CmdCmd(args string) error { b.needCommit = true - b.config.Cmd = []string{"/bin/sh", "-c", args} + var cmd []string + if err := json.Unmarshal([]byte(args), &cmd); err != nil { + b.config.Cmd = []string{"/bin/sh", "-c", args} + } else { + b.config.Cmd = cmd + } return nil } From 3a9ef5f9bbae19ae5ac4108dbbaed649e26d942e Mon Sep 17 00:00:00 2001 From: Eric Hanchrow Date: Mon, 20 May 2013 16:29:57 -0700 Subject: [PATCH 25/95] Install curl; nix stray backslash; use proper IP address --- docs/sources/examples/python_web_app.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/sources/examples/python_web_app.rst b/docs/sources/examples/python_web_app.rst index 992a09dc4..678b8cd65 100644 --- a/docs/sources/examples/python_web_app.rst +++ b/docs/sources/examples/python_web_app.rst @@ -70,7 +70,8 @@ lookup the public-facing port which is NAT-ed store the private port used by the .. code-block:: bash - curl \http://`hostname`:$WEB_PORT + sudo aptitude install curl + curl http://127.0.0.1:$WEB_PORT Hello world! access the web app using curl. If everything worked as planned you should see the line "Hello world!" inside of your console. From f35f084059e5c34940f74f55ad32ecfcd78ce61c Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Mon, 20 May 2013 16:35:28 -0700 Subject: [PATCH 26/95] Use pointers for the object methods --- builder_client.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/builder_client.go b/builder_client.go index 0c283d259..45e191ea3 100644 --- a/builder_client.go +++ b/builder_client.go @@ -31,7 +31,7 @@ type builderClient struct { needCommit bool } -func (b builderClient) clearTmp(containers, images map[string]struct{}) { +func (b *builderClient) clearTmp(containers, images map[string]struct{}) { for c := range containers { if _, _, err := b.cli.call("DELETE", "/containers/"+c, nil); err != nil { utils.Debugf("%s", err) @@ -46,7 +46,7 @@ func (b builderClient) clearTmp(containers, images map[string]struct{}) { } } -func (b builderClient) CmdFrom(name string) error { +func (b *builderClient) CmdFrom(name string) error { obj, statusCode, err := b.cli.call("GET", "/images/"+name+"/json", nil) if statusCode == 404 { if err := b.cli.hijack("POST", "/images/create?fromImage="+name, false); err != nil { @@ -66,16 +66,17 @@ func (b builderClient) CmdFrom(name string) error { return err } b.image = img.Id + utils.Debugf("Using image %s", b.image) return nil } -func (b builderClient) CmdMaintainer(name string) error { +func (b *builderClient) CmdMaintainer(name string) error { b.needCommit = true b.maintainer = name return nil } -func (b builderClient) CmdRun(args string) error { +func (b *builderClient) CmdRun(args string) error { if b.image == "" { return fmt.Errorf("Please provide a source image with `from` prior to run") } @@ -111,7 +112,7 @@ func (b builderClient) CmdRun(args string) error { return b.commit(cid) } -func (b builderClient) CmdEnv(args string) error { +func (b *builderClient) CmdEnv(args string) error { b.needCommit = true tmp := strings.SplitN(args, " ", 2) if len(tmp) != 2 { @@ -130,10 +131,11 @@ func (b builderClient) CmdEnv(args string) error { return nil } -func (b builderClient) CmdCmd(args string) error { +func (b *builderClient) CmdCmd(args string) error { b.needCommit = true var cmd []string if err := json.Unmarshal([]byte(args), &cmd); err != nil { + utils.Debugf("Error unmarshalling: %s, using /bin/sh -c", err) b.config.Cmd = []string{"/bin/sh", "-c", args} } else { b.config.Cmd = cmd @@ -141,19 +143,19 @@ func (b builderClient) CmdCmd(args string) error { return nil } -func (b builderClient) CmdExpose(args string) error { +func (b *builderClient) CmdExpose(args string) error { ports := strings.Split(args, " ") b.config.PortSpecs = append(ports, b.config.PortSpecs...) return nil } -func (b builderClient) CmdInsert(args string) error { +func (b *builderClient) CmdInsert(args string) error { // FIXME: Reimplement this once the remove_hijack branch gets merged. // We need to retrieve the resulting Id return fmt.Errorf("INSERT not implemented") } -func (b builderClient) run() (string, error) { +func (b *builderClient) run() (string, error) { if b.image == "" { return "", fmt.Errorf("Please provide a source image with `from` prior to run") } @@ -194,7 +196,7 @@ func (b builderClient) run() (string, error) { return apiRun.Id, nil } -func (b builderClient) commit(id string) error { +func (b *builderClient) commit(id string) error { if b.image == "" { return fmt.Errorf("Please provide a source image with `from` prior to run") } @@ -230,7 +232,7 @@ func (b builderClient) commit(id string) error { return nil } -func (b builderClient) Build(dockerfile io.Reader) (string, error) { +func (b *builderClient) Build(dockerfile io.Reader) (string, error) { // defer b.clearTmp(tmpContainers, tmpImages) file := bufio.NewReader(dockerfile) for { @@ -253,7 +255,7 @@ func (b builderClient) Build(dockerfile io.Reader) (string, error) { instruction := strings.ToLower(strings.Trim(tmp[0], " ")) arguments := strings.Trim(tmp[1], " ") - fmt.Printf("%s %s\n", strings.ToUpper(instruction), arguments) + fmt.Printf("%s %s (%s)\n", strings.ToUpper(instruction), arguments, b.image) method, exists := reflect.TypeOf(b).MethodByName("Cmd" + strings.ToUpper(instruction[:1]) + strings.ToLower(instruction[1:])) if !exists { From 49505c599b3a65196b6b6f746f4bfad3a417dd7a Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Mon, 20 May 2013 17:30:33 -0700 Subject: [PATCH 27/95] Fix an issue trying to pull specific tag --- builder_client.go | 18 ++++++++++++++++-- server.go | 9 ++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/builder_client.go b/builder_client.go index 45e191ea3..ceeab002c 100644 --- a/builder_client.go +++ b/builder_client.go @@ -49,7 +49,21 @@ func (b *builderClient) clearTmp(containers, images map[string]struct{}) { func (b *builderClient) CmdFrom(name string) error { obj, statusCode, err := b.cli.call("GET", "/images/"+name+"/json", nil) if statusCode == 404 { - if err := b.cli.hijack("POST", "/images/create?fromImage="+name, false); err != nil { + + remote := name + var tag string + if strings.Contains(remote, ":") { + remoteParts := strings.Split(remote, ":") + tag = remoteParts[1] + remote = remoteParts[0] + } + var out io.Writer + if os.Getenv("DEBUG") != "" { + out = os.Stdout + } else { + out = &utils.NopWriter{} + } + if err := b.cli.stream("POST", "/images/create?fromImage="+remote+"&tag="+tag, nil, out); err != nil { return err } obj, _, err = b.cli.call("GET", "/images/"+name+"/json", nil) @@ -233,7 +247,7 @@ func (b *builderClient) commit(id string) error { } func (b *builderClient) Build(dockerfile io.Reader) (string, error) { - // defer b.clearTmp(tmpContainers, tmpImages) + defer b.clearTmp(b.tmpContainers, b.tmpImages) file := bufio.NewReader(dockerfile) for { line, err := file.ReadString('\n') diff --git a/server.go b/server.go index e9cc44de6..564b1c812 100644 --- a/server.go +++ b/server.go @@ -363,7 +363,7 @@ func (srv *Server) pullRepository(out io.Writer, remote, askedTag string) error for _, img := range repoData.ImgList { if askedTag != "" && img.Tag != askedTag { - utils.Debugf("%s does not match %s, skipping", img.Tag, askedTag) + utils.Debugf("(%s) does not match %s (id: %s), skipping", img.Tag, askedTag, img.Id) continue } fmt.Fprintf(out, "Pulling image %s (%s) from %s\n", img.Id, img.Tag, remote) @@ -380,11 +380,10 @@ func (srv *Server) pullRepository(out io.Writer, remote, askedTag string) error return fmt.Errorf("Could not find repository on any of the indexed registries.") } } - // If we asked for a specific tag, do not register the others - if askedTag != "" { - return nil - } for tag, id := range tagsList { + if askedTag != "" && tag != askedTag { + continue + } if err := srv.runtime.repositories.Set(remote, tag, id, true); err != nil { return err } From 218812eb3cfeb5c5253ed6a54ed3e45c1107ffd1 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Mon, 20 May 2013 17:52:39 -0700 Subject: [PATCH 28/95] Update docker builder doc --- docs/sources/use/builder.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/sources/use/builder.rst b/docs/sources/use/builder.rst index 735b2e575..84d275782 100644 --- a/docs/sources/use/builder.rst +++ b/docs/sources/use/builder.rst @@ -107,8 +107,7 @@ The `ENV` instruction sets the environment variable `` to the value functionally equivalent to prefixing the command with `=` .. note:: - The environment variables are local to the Dockerfile, they will not persist - when a container is run from the resulting image. + The environment variables will persist when a container is run from the resulting image. 2.7 INSERT ---------- @@ -122,6 +121,8 @@ curl was installed within the image. .. note:: The path must include the file name. +.. note:: + This instruction has temporarily disabled 3. Dockerfile Examples ====================== @@ -179,4 +180,4 @@ curl was installed within the image. # Will output something like ===> 695d7793cbe4 # You'll now have two images, 907ad6c2736f with /bar, and 695d7793cbe4 with - # /oink. \ No newline at end of file + # /oink. From 3f22842542a17d41f72b4943d19d244f2296b418 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Mon, 20 May 2013 17:54:54 -0700 Subject: [PATCH 29/95] Remove no longer needed tests --- api_test.go | 35 ------------------- builder_test.go | 89 ------------------------------------------------- 2 files changed, 124 deletions(-) delete mode 100644 builder_test.go diff --git a/api_test.go b/api_test.go index 700d2c4b2..dd685ffec 100644 --- a/api_test.go +++ b/api_test.go @@ -14,7 +14,6 @@ import ( "net/http/httptest" "os" "path" - "strings" "testing" "time" ) @@ -579,40 +578,6 @@ func TestPostCommit(t *testing.T) { } } -func TestPostBuild(t *testing.T) { - runtime, err := newTestRuntime() - if err != nil { - t.Fatal(err) - } - defer nuke(runtime) - - srv := &Server{runtime: runtime} - - imgs, err := runtime.graph.All() - if err != nil { - t.Fatal(err) - } - beginCount := len(imgs) - - req, err := http.NewRequest("POST", "/build", strings.NewReader(Dockerfile)) - if err != nil { - t.Fatal(err) - } - - r := httptest.NewRecorder() - if err := postBuild(srv, r, req, nil); err != nil { - t.Fatal(err) - } - - imgs, err = runtime.graph.All() - if err != nil { - t.Fatal(err) - } - if len(imgs) != beginCount+3 { - t.Fatalf("Expected %d images, %d found", beginCount+3, len(imgs)) - } -} - func TestPostImagesCreate(t *testing.T) { // FIXME: Use the staging in order to perform tests diff --git a/builder_test.go b/builder_test.go deleted file mode 100644 index e3a24e86e..000000000 --- a/builder_test.go +++ /dev/null @@ -1,89 +0,0 @@ -package docker - -import ( - "github.com/dotcloud/docker/utils" - "strings" - "testing" -) - -const Dockerfile = ` -# VERSION 0.1 -# DOCKER-VERSION 0.2 - -from ` + unitTestImageName + ` -run sh -c 'echo root:testpass > /tmp/passwd' -run mkdir -p /var/run/sshd -insert https://raw.github.com/dotcloud/docker/master/CHANGELOG.md /tmp/CHANGELOG.md -` - -func TestBuild(t *testing.T) { - runtime, err := newTestRuntime() - if err != nil { - t.Fatal(err) - } - defer nuke(runtime) - - builder := NewBuilder(runtime) - - img, err := builder.Build(strings.NewReader(Dockerfile), &utils.NopWriter{}) - if err != nil { - t.Fatal(err) - } - - container, err := builder.Create( - &Config{ - Image: img.Id, - Cmd: []string{"cat", "/tmp/passwd"}, - }, - ) - if err != nil { - t.Fatal(err) - } - defer runtime.Destroy(container) - - output, err := container.Output() - if err != nil { - t.Fatal(err) - } - if string(output) != "root:testpass\n" { - t.Fatalf("Unexpected output. Read '%s', expected '%s'", output, "root:testpass\n") - } - - container2, err := builder.Create( - &Config{ - Image: img.Id, - Cmd: []string{"ls", "-d", "/var/run/sshd"}, - }, - ) - if err != nil { - t.Fatal(err) - } - defer runtime.Destroy(container2) - - output, err = container2.Output() - if err != nil { - t.Fatal(err) - } - if string(output) != "/var/run/sshd\n" { - t.Fatal("/var/run/sshd has not been created") - } - - container3, err := builder.Create( - &Config{ - Image: img.Id, - Cmd: []string{"cat", "/tmp/CHANGELOG.md"}, - }, - ) - if err != nil { - t.Fatal(err) - } - defer runtime.Destroy(container3) - - output, err = container3.Output() - if err != nil { - t.Fatal(err) - } - if len(output) == 0 { - t.Fatal("/tmp/CHANGELOG.md has not been copied") - } -} From a3ccec197e847a996e725d87177067dba98bcca6 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Tue, 21 May 2013 10:14:58 +0000 Subject: [PATCH 30/95] add -host and -port --- commands.go | 4 ++-- docker/docker.go | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/commands.go b/commands.go index 5e459a1d9..0d7dc0e8a 100644 --- a/commands.go +++ b/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/docker/docker.go b/docker/docker.go index c8c1a6560..800c8f09c 100644 --- a/docker/docker.go +++ b/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 5818813183bfb61180846f2b1b23a6fdcb2c9cdd Mon Sep 17 00:00:00 2001 From: Christopher Currie Date: Tue, 21 May 2013 21:45:27 -0600 Subject: [PATCH 31/95] Apparent typos in the docs. --- docs/sources/examples/python_web_app.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/sources/examples/python_web_app.rst b/docs/sources/examples/python_web_app.rst index 992a09dc4..3dd25015f 100644 --- a/docs/sources/examples/python_web_app.rst +++ b/docs/sources/examples/python_web_app.rst @@ -40,7 +40,7 @@ We attach to the new container to see what is going on. Ctrl-C to disconnect .. code-block:: bash - BUILD_IMG=$(docker commit $BUILD_JOB _/builds/github.com/hykes/helloflask/master) + BUILD_IMG=$(docker commit $BUILD_JOB _/builds/github.com/shykes/helloflask/master) Save the changed we just made in the container to a new image called "_/builds/github.com/hykes/helloflask/master" and save the image id in the BUILD_IMG variable name. @@ -58,7 +58,7 @@ Use the new image we just created and create a new container with network port 5 .. code-block:: bash docker logs $WEB_WORKER - * Running on \http://0.0.0.0:5000/ + * Running on http://0.0.0.0:5000/ view the logs for the new container using the WEB_WORKER variable, and if everything worked as planned you should see the line "Running on http://0.0.0.0:5000/" in the log output. @@ -70,7 +70,7 @@ lookup the public-facing port which is NAT-ed store the private port used by the .. code-block:: bash - curl \http://`hostname`:$WEB_PORT + curl http://`hostname`:$WEB_PORT Hello world! access the web app using curl. If everything worked as planned you should see the line "Hello world!" inside of your console. From 949a649cc2364f796daae14fa3b044432e25efdf Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 22 May 2013 13:49:12 +0000 Subject: [PATCH 32/95] fix content type in doc --- docs/sources/api/docker_remote_api.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/sources/api/docker_remote_api.rst b/docs/sources/api/docker_remote_api.rst index 2b1aad0e8..5d62963b4 100644 --- a/docs/sources/api/docker_remote_api.rst +++ b/docs/sources/api/docker_remote_api.rst @@ -118,7 +118,8 @@ Create a container .. sourcecode:: http HTTP/1.1 201 OK - + Content-Type: application/json + { "Id":"e90e34656806" "Warnings":[] From faae7220c019882a2160aeea6bebc46c15d702be Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 22 May 2013 15:29:54 +0000 Subject: [PATCH 33/95] api versionning --- api.go | 76 +++++++++++++++++++++++++++++++---------------------- api_test.go | 52 ++++++++++++++++++------------------ commands.go | 10 +++---- 3 files changed, 75 insertions(+), 63 deletions(-) diff --git a/api.go b/api.go index 29103fac1..0a902c404 100644 --- a/api.go +++ b/api.go @@ -13,6 +13,8 @@ import ( "strings" ) +const API_VERSION = 1.0 + func hijackServer(w http.ResponseWriter) (io.ReadCloser, io.Writer, error) { conn, _, err := w.(http.Hijacker).Hijack() if err != nil { @@ -56,7 +58,7 @@ func getBoolParam(value string) (bool, error) { return false, fmt.Errorf("Bad parameter") } -func getAuth(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) 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()) if err != nil { return err @@ -65,7 +67,7 @@ func getAuth(srv *Server, w http.ResponseWriter, r *http.Request, vars map[strin return nil } -func postAuth(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func postAuth(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { config := &auth.AuthConfig{} if err := json.NewDecoder(r.Body).Decode(config); err != nil { return err @@ -94,7 +96,7 @@ func postAuth(srv *Server, w http.ResponseWriter, r *http.Request, vars map[stri return nil } -func getVersion(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func getVersion(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { m := srv.DockerVersion() b, err := json.Marshal(m) if err != nil { @@ -104,7 +106,7 @@ func getVersion(srv *Server, w http.ResponseWriter, r *http.Request, vars map[st return nil } -func postContainersKill(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func postContainersKill(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if vars == nil { return fmt.Errorf("Missing parameter") } @@ -116,7 +118,7 @@ func postContainersKill(srv *Server, w http.ResponseWriter, r *http.Request, var return nil } -func getContainersExport(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func getContainersExport(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if vars == nil { return fmt.Errorf("Missing parameter") } @@ -129,7 +131,7 @@ func getContainersExport(srv *Server, w http.ResponseWriter, r *http.Request, va return nil } -func getImagesJson(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func getImagesJson(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := parseForm(r); err != nil { return err } @@ -152,14 +154,14 @@ func getImagesJson(srv *Server, w http.ResponseWriter, r *http.Request, vars map return nil } -func getImagesViz(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func getImagesViz(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := srv.ImagesViz(w); err != nil { return err } return nil } -func getInfo(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func getInfo(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { out := srv.DockerInfo() b, err := json.Marshal(out) if err != nil { @@ -169,7 +171,7 @@ func getInfo(srv *Server, w http.ResponseWriter, r *http.Request, vars map[strin return nil } -func getImagesHistory(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func getImagesHistory(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if vars == nil { return fmt.Errorf("Missing parameter") } @@ -186,7 +188,7 @@ func getImagesHistory(srv *Server, w http.ResponseWriter, r *http.Request, vars return nil } -func getContainersChanges(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func getContainersChanges(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if vars == nil { return fmt.Errorf("Missing parameter") } @@ -203,7 +205,7 @@ func getContainersChanges(srv *Server, w http.ResponseWriter, r *http.Request, v return nil } -func getContainersPs(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func getContainersPs(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := parseForm(r); err != nil { return err } @@ -227,7 +229,7 @@ func getContainersPs(srv *Server, w http.ResponseWriter, r *http.Request, vars m return nil } -func postImagesTag(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func postImagesTag(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := parseForm(r); err != nil { return err } @@ -249,7 +251,7 @@ func postImagesTag(srv *Server, w http.ResponseWriter, r *http.Request, vars map return nil } -func postCommit(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func postCommit(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := parseForm(r); err != nil { return err } @@ -276,7 +278,7 @@ func postCommit(srv *Server, w http.ResponseWriter, r *http.Request, vars map[st } // Creates an image from Pull or from Import -func postImagesCreate(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func postImagesCreate(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := parseForm(r); err != nil { return err } @@ -299,7 +301,7 @@ func postImagesCreate(srv *Server, w http.ResponseWriter, r *http.Request, vars return nil } -func getImagesSearch(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func getImagesSearch(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := parseForm(r); err != nil { return err } @@ -317,7 +319,7 @@ func getImagesSearch(srv *Server, w http.ResponseWriter, r *http.Request, vars m return nil } -func postImagesInsert(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func postImagesInsert(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := parseForm(r); err != nil { return err } @@ -335,7 +337,7 @@ func postImagesInsert(srv *Server, w http.ResponseWriter, r *http.Request, vars return nil } -func postImagesPush(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func postImagesPush(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := parseForm(r); err != nil { return err } @@ -352,7 +354,7 @@ func postImagesPush(srv *Server, w http.ResponseWriter, r *http.Request, vars ma return nil } -func postContainersCreate(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func postContainersCreate(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { config := &Config{} if err := json.NewDecoder(r.Body).Decode(config); err != nil { return err @@ -382,7 +384,7 @@ func postContainersCreate(srv *Server, w http.ResponseWriter, r *http.Request, v return nil } -func postContainersRestart(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func postContainersRestart(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := parseForm(r); err != nil { return err } @@ -401,7 +403,7 @@ func postContainersRestart(srv *Server, w http.ResponseWriter, r *http.Request, return nil } -func deleteContainers(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func deleteContainers(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := parseForm(r); err != nil { return err } @@ -421,7 +423,7 @@ func deleteContainers(srv *Server, w http.ResponseWriter, r *http.Request, vars return nil } -func deleteImages(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func deleteImages(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if vars == nil { return fmt.Errorf("Missing parameter") } @@ -433,7 +435,7 @@ func deleteImages(srv *Server, w http.ResponseWriter, r *http.Request, vars map[ return nil } -func postContainersStart(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func postContainersStart(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if vars == nil { return fmt.Errorf("Missing parameter") } @@ -445,7 +447,7 @@ func postContainersStart(srv *Server, w http.ResponseWriter, r *http.Request, va return nil } -func postContainersStop(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func postContainersStop(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := parseForm(r); err != nil { return err } @@ -466,7 +468,7 @@ func postContainersStop(srv *Server, w http.ResponseWriter, r *http.Request, var return nil } -func postContainersWait(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func postContainersWait(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if vars == nil { return fmt.Errorf("Missing parameter") } @@ -483,7 +485,7 @@ func postContainersWait(srv *Server, w http.ResponseWriter, r *http.Request, var return nil } -func postContainersAttach(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func postContainersAttach(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := parseForm(r); err != nil { return err } @@ -526,7 +528,7 @@ func postContainersAttach(srv *Server, w http.ResponseWriter, r *http.Request, v return nil } -func getContainersByName(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func getContainersByName(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if vars == nil { return fmt.Errorf("Missing parameter") } @@ -544,7 +546,7 @@ func getContainersByName(srv *Server, w http.ResponseWriter, r *http.Request, va return nil } -func getImagesByName(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func getImagesByName(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if vars == nil { return fmt.Errorf("Missing parameter") } @@ -562,7 +564,7 @@ func getImagesByName(srv *Server, w http.ResponseWriter, r *http.Request, vars m return nil } -func postImagesGetCache(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func postImagesGetCache(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { apiConfig := &ApiImageConfig{} if err := json.NewDecoder(r.Body).Decode(apiConfig); err != nil { return err @@ -589,7 +591,7 @@ func ListenAndServe(addr string, srv *Server, logging bool) error { r := mux.NewRouter() log.Printf("Listening for HTTP on %s\n", addr) - m := map[string]map[string]func(*Server, http.ResponseWriter, *http.Request, map[string]string) error{ + m := map[string]map[string]func(*Server, float64, http.ResponseWriter, *http.Request, map[string]string) error{ "GET": { "/auth": getAuth, "/version": getVersion, @@ -633,7 +635,7 @@ func ListenAndServe(addr string, srv *Server, logging bool) error { localRoute := route localMethod := method localFct := fct - r.Path(localRoute).Methods(localMethod).HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + f := func(w http.ResponseWriter, r *http.Request) { utils.Debugf("Calling %s %s", localMethod, localRoute) if logging { log.Println(r.Method, r.RequestURI) @@ -644,10 +646,20 @@ func ListenAndServe(addr string, srv *Server, logging bool) error { utils.Debugf("Warning: client and server don't have the same version (client: %s, server: %s)", userAgent[1], VERSION) } } - if err := localFct(srv, w, r, mux.Vars(r)); err != nil { + version, err := strconv.ParseFloat(mux.Vars(r)["version"], 64) + if err != nil { + version = API_VERSION + } + if version == 0 || version > API_VERSION { + w.WriteHeader(http.StatusNotFound) + return + } + if err := localFct(srv, version, w, r, mux.Vars(r)); err != nil { httpError(w, err) } - }) + } + r.Path("/v{version:[0-9.]+}" + localRoute).Methods(localMethod).HandlerFunc(f) + r.Path(localRoute).Methods(localMethod).HandlerFunc(f) } } diff --git a/api_test.go b/api_test.go index dd685ffec..de4289728 100644 --- a/api_test.go +++ b/api_test.go @@ -48,7 +48,7 @@ func TestGetAuth(t *testing.T) { t.Fatal(err) } - if err := postAuth(srv, r, req, nil); err != nil { + if err := postAuth(srv, API_VERSION, r, req, nil); err != nil { t.Fatal(err) } @@ -74,7 +74,7 @@ func TestGetVersion(t *testing.T) { r := httptest.NewRecorder() - if err := getVersion(srv, r, nil, nil); err != nil { + if err := getVersion(srv, API_VERSION, r, nil, nil); err != nil { t.Fatal(err) } @@ -98,7 +98,7 @@ func TestGetInfo(t *testing.T) { r := httptest.NewRecorder() - if err := getInfo(srv, r, nil, nil); err != nil { + if err := getInfo(srv, API_VERSION, r, nil, nil); err != nil { t.Fatal(err) } @@ -129,7 +129,7 @@ func TestGetImagesJson(t *testing.T) { r := httptest.NewRecorder() - if err := getImagesJson(srv, r, req, nil); err != nil { + if err := getImagesJson(srv, API_VERSION, r, req, nil); err != nil { t.Fatal(err) } @@ -154,7 +154,7 @@ func TestGetImagesJson(t *testing.T) { t.Fatal(err) } - if err := getImagesJson(srv, r2, req2, nil); err != nil { + if err := getImagesJson(srv, API_VERSION, r2, req2, nil); err != nil { t.Fatal(err) } @@ -179,7 +179,7 @@ func TestGetImagesJson(t *testing.T) { t.Fatal(err) } - if err := getImagesJson(srv, r3, req3, nil); err != nil { + if err := getImagesJson(srv, API_VERSION, r3, req3, nil); err != nil { t.Fatal(err) } @@ -200,7 +200,7 @@ func TestGetImagesJson(t *testing.T) { t.Fatal(err) } - err = getImagesJson(srv, r4, req4, nil) + err = getImagesJson(srv, API_VERSION, r4, req4, nil) if err == nil { t.Fatalf("Error expected, received none") } @@ -221,7 +221,7 @@ func TestGetImagesViz(t *testing.T) { srv := &Server{runtime: runtime} r := httptest.NewRecorder() - if err := getImagesViz(srv, r, nil, nil); err != nil { + if err := getImagesViz(srv, API_VERSION, r, nil, nil); err != nil { t.Fatal(err) } @@ -258,7 +258,7 @@ func TestGetImagesSearch(t *testing.T) { t.Fatal(err) } - if err := getImagesSearch(srv, r, req, nil); err != nil { + if err := getImagesSearch(srv, API_VERSION, r, req, nil); err != nil { t.Fatal(err) } @@ -282,7 +282,7 @@ func TestGetImagesHistory(t *testing.T) { r := httptest.NewRecorder() - if err := getImagesHistory(srv, r, nil, map[string]string{"name": unitTestImageName}); err != nil { + if err := getImagesHistory(srv, API_VERSION, r, nil, map[string]string{"name": unitTestImageName}); err != nil { t.Fatal(err) } @@ -305,7 +305,7 @@ func TestGetImagesByName(t *testing.T) { srv := &Server{runtime: runtime} r := httptest.NewRecorder() - if err := getImagesByName(srv, r, nil, map[string]string{"name": unitTestImageName}); err != nil { + if err := getImagesByName(srv, API_VERSION, r, nil, map[string]string{"name": unitTestImageName}); err != nil { t.Fatal(err) } @@ -342,7 +342,7 @@ func TestGetContainersPs(t *testing.T) { } r := httptest.NewRecorder() - if err := getContainersPs(srv, r, req, nil); err != nil { + if err := getContainersPs(srv, API_VERSION, r, req, nil); err != nil { t.Fatal(err) } containers := []ApiContainers{} @@ -385,7 +385,7 @@ func TestGetContainersExport(t *testing.T) { } r := httptest.NewRecorder() - if err = getContainersExport(srv, r, nil, map[string]string{"name": container.Id}); err != nil { + if err = getContainersExport(srv, API_VERSION, r, nil, map[string]string{"name": container.Id}); err != nil { t.Fatal(err) } @@ -440,7 +440,7 @@ func TestGetContainersChanges(t *testing.T) { } r := httptest.NewRecorder() - if err := getContainersChanges(srv, r, nil, map[string]string{"name": container.Id}); err != nil { + if err := getContainersChanges(srv, API_VERSION, r, nil, map[string]string{"name": container.Id}); err != nil { t.Fatal(err) } changes := []Change{} @@ -484,7 +484,7 @@ func TestGetContainersByName(t *testing.T) { defer runtime.Destroy(container) r := httptest.NewRecorder() - if err := getContainersByName(srv, r, nil, map[string]string{"name": container.Id}); err != nil { + if err := getContainersByName(srv, API_VERSION, r, nil, map[string]string{"name": container.Id}); err != nil { t.Fatal(err) } outContainer := &Container{} @@ -515,7 +515,7 @@ func TestPostAuth(t *testing.T) { srv.registry.ResetClient(authConfigOrig) r := httptest.NewRecorder() - if err := getAuth(srv, r, nil, nil); err != nil { + if err := getAuth(srv, API_VERSION, r, nil, nil); err != nil { t.Fatal(err) } @@ -562,7 +562,7 @@ func TestPostCommit(t *testing.T) { } r := httptest.NewRecorder() - if err := postCommit(srv, r, req, nil); err != nil { + if err := postCommit(srv, API_VERSION, r, req, nil); err != nil { t.Fatal(err) } if r.Code != http.StatusCreated { @@ -840,7 +840,7 @@ func TestPostContainersCreate(t *testing.T) { } r := httptest.NewRecorder() - if err := postContainersCreate(srv, r, req, nil); err != nil { + if err := postContainersCreate(srv, API_VERSION, r, req, nil); err != nil { t.Fatal(err) } if r.Code != http.StatusCreated { @@ -903,7 +903,7 @@ func TestPostContainersKill(t *testing.T) { } r := httptest.NewRecorder() - if err := postContainersKill(srv, r, nil, map[string]string{"name": container.Id}); err != nil { + if err := postContainersKill(srv, API_VERSION, r, nil, map[string]string{"name": container.Id}); err != nil { t.Fatal(err) } if r.Code != http.StatusNoContent { @@ -951,7 +951,7 @@ func TestPostContainersRestart(t *testing.T) { t.Fatal(err) } r := httptest.NewRecorder() - if err := postContainersRestart(srv, r, req, map[string]string{"name": container.Id}); err != nil { + if err := postContainersRestart(srv, API_VERSION, r, req, map[string]string{"name": container.Id}); err != nil { t.Fatal(err) } if r.Code != http.StatusNoContent { @@ -992,7 +992,7 @@ func TestPostContainersStart(t *testing.T) { defer runtime.Destroy(container) r := httptest.NewRecorder() - if err := postContainersStart(srv, r, nil, map[string]string{"name": container.Id}); err != nil { + if err := postContainersStart(srv, API_VERSION, r, nil, map[string]string{"name": container.Id}); err != nil { t.Fatal(err) } if r.Code != http.StatusNoContent { @@ -1007,7 +1007,7 @@ func TestPostContainersStart(t *testing.T) { } r = httptest.NewRecorder() - if err = postContainersStart(srv, r, nil, map[string]string{"name": container.Id}); err == nil { + if err = postContainersStart(srv, API_VERSION, r, nil, map[string]string{"name": container.Id}); err == nil { t.Fatalf("A running containter should be able to be started") } @@ -1054,7 +1054,7 @@ func TestPostContainersStop(t *testing.T) { t.Fatal(err) } r := httptest.NewRecorder() - if err := postContainersStop(srv, r, req, map[string]string{"name": container.Id}); err != nil { + if err := postContainersStop(srv, API_VERSION, r, req, map[string]string{"name": container.Id}); err != nil { t.Fatal(err) } if r.Code != http.StatusNoContent { @@ -1092,7 +1092,7 @@ func TestPostContainersWait(t *testing.T) { setTimeout(t, "Wait timed out", 3*time.Second, func() { r := httptest.NewRecorder() - if err := postContainersWait(srv, r, nil, map[string]string{"name": container.Id}); err != nil { + if err := postContainersWait(srv, API_VERSION, r, nil, map[string]string{"name": container.Id}); err != nil { t.Fatal(err) } apiWait := &ApiWait{} @@ -1154,7 +1154,7 @@ func TestPostContainersAttach(t *testing.T) { t.Fatal(err) } - if err := postContainersAttach(srv, r, req, map[string]string{"name": container.Id}); err != nil { + if err := postContainersAttach(srv, API_VERSION, r, req, map[string]string{"name": container.Id}); err != nil { t.Fatal(err) } }() @@ -1224,7 +1224,7 @@ func TestDeleteContainers(t *testing.T) { t.Fatal(err) } r := httptest.NewRecorder() - if err := deleteContainers(srv, r, req, map[string]string{"name": container.Id}); err != nil { + if err := deleteContainers(srv, API_VERSION, r, req, map[string]string{"name": container.Id}); err != nil { t.Fatal(err) } if r.Code != http.StatusNoContent { diff --git a/commands.go b/commands.go index 5e459a1d9..17d7e08ff 100644 --- a/commands.go +++ b/commands.go @@ -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/v%f", cli.host, cli.port, API_VERSION)+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/v%f%s", cli.host, 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, path, nil) + req, err := http.NewRequest(method, fmt.Sprintf("/v%f%s", API_VERSION, path), nil) if err != nil { return err } @@ -1294,6 +1294,6 @@ func NewDockerCli(host string, port int) *DockerCli { } type DockerCli struct { - host string - port int + host string + port int } From 800b401f0ba706f8f09b5beacd335caf4548e63c Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 22 May 2013 16:15:52 +0000 Subject: [PATCH 34/95] improved doc and usage --- commands.go | 2 +- docs/sources/commandline/cli.rst | 4 +++- docs/sources/use/basics.rst | 13 +++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/commands.go b/commands.go index 0d7dc0e8a..50f8533a2 100644 --- a/commands.go +++ b/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/docs/sources/commandline/cli.rst b/docs/sources/commandline/cli.rst index 1a341d3e5..8ea3d1935 100644 --- a/docs/sources/commandline/cli.rst +++ b/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/docs/sources/use/basics.rst b/docs/sources/use/basics.rst index ffd2a7b96..9a5f8faf4 100644 --- a/docs/sources/use/basics.rst +++ b/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 056698b67678d7dd687e08401386c35cd5cb9d77 Mon Sep 17 00:00:00 2001 From: Eric Hanchrow Date: Wed, 22 May 2013 12:54:50 -0700 Subject: [PATCH 35/95] Use 127.0.0.1 instead of `hostname` in the "access the web app" section. --- docs/sources/examples/python_web_app.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sources/examples/python_web_app.rst b/docs/sources/examples/python_web_app.rst index 8f662cbf1..952ef62e3 100644 --- a/docs/sources/examples/python_web_app.rst +++ b/docs/sources/examples/python_web_app.rst @@ -71,7 +71,7 @@ lookup the public-facing port which is NAT-ed store the private port used by the .. code-block:: bash # install curl if necessary, then ... - curl http://`hostname`:$WEB_PORT + curl http://127.0.0.1:$WEB_PORT Hello world! access the web app using curl. If everything worked as planned you should see the line "Hello world!" inside of your console. From f008d1107c1702a2c3337e4515c6f72db557013b Mon Sep 17 00:00:00 2001 From: Thatcher Peskens Date: Wed, 22 May 2013 16:04:33 -0700 Subject: [PATCH 36/95] Fix broken image on README, closes #680 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c83feeae5..918fdaade 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Docker is an open-source implementation of the deployment engine which powers [d It benefits directly from the experience accumulated over several years of large-scale operation and support of hundreds of thousands of applications and databases. -![Docker L](docs/sources/static_files/lego_docker.jpg "Docker") +![Docker L](docs/sources/concepts/images/lego_docker.jpg "Docker") ## Better than VMs From 18cb5c9314dbc9a0aa857211b124a3feb85c5274 Mon Sep 17 00:00:00 2001 From: rogaha Date: Tue, 21 May 2013 11:47:16 -0600 Subject: [PATCH 37/95] added/modifed tittle, description and keywords changed the title prefix to sufix + Documentation --- docs/sources/api/docker_remote_api.rst | 4 ++++ docs/sources/api/index.rst | 4 ++-- docs/sources/api/registry_api.rst | 2 +- docs/sources/commandline/command/attach.rst | 4 ++++ docs/sources/commandline/command/build.rst | 4 ++++ docs/sources/commandline/command/commit.rst | 4 ++++ docs/sources/commandline/command/diff.rst | 4 ++++ docs/sources/commandline/command/export.rst | 4 ++++ docs/sources/commandline/command/history.rst | 4 ++++ docs/sources/commandline/command/images.rst | 4 ++++ docs/sources/commandline/command/import.rst | 4 ++++ docs/sources/commandline/command/info.rst | 4 ++++ docs/sources/commandline/command/inspect.rst | 4 ++++ docs/sources/commandline/command/kill.rst | 4 ++++ docs/sources/commandline/command/login.rst | 4 ++++ docs/sources/commandline/command/logs.rst | 4 ++++ docs/sources/commandline/command/port.rst | 4 ++++ docs/sources/commandline/command/ps.rst | 4 ++++ docs/sources/commandline/command/pull.rst | 4 ++++ docs/sources/commandline/command/push.rst | 4 ++++ docs/sources/commandline/command/restart.rst | 4 ++++ docs/sources/commandline/command/rm.rst | 4 ++++ docs/sources/commandline/command/rmi.rst | 4 ++++ docs/sources/commandline/command/run.rst | 4 ++++ docs/sources/commandline/command/search.rst | 4 ++++ docs/sources/commandline/command/start.rst | 4 ++++ docs/sources/commandline/command/stop.rst | 4 ++++ docs/sources/commandline/command/tag.rst | 4 ++++ docs/sources/commandline/command/version.rst | 4 ++++ docs/sources/commandline/command/wait.rst | 4 ++++ docs/sources/commandline/index.rst | 4 ++-- docs/sources/concepts/buildingblocks.rst | 2 +- docs/sources/concepts/containers.rst | 2 +- docs/sources/concepts/index.rst | 4 ++-- docs/sources/contributing/contributing.rst | 4 ++++ docs/sources/faq.rst | 4 ++++ docs/sources/index/variable.rst | 4 ++++ docs/sources/installation/amazon.rst | 4 ++++ docs/sources/installation/archlinux.rst | 4 ++++ docs/sources/installation/binaries.rst | 4 ++++ docs/sources/installation/index.rst | 4 ++-- docs/sources/installation/kernel.rst | 4 ++++ docs/sources/installation/rackspace.rst | 4 ++++ docs/sources/installation/ubuntulinux.rst | 4 ++++ docs/sources/installation/upgrading.rst | 4 ++++ docs/sources/installation/vagrant.rst | 3 +++ docs/sources/toctree.rst | 6 +++--- docs/sources/use/basics.rst | 4 ++-- docs/sources/use/builder.rst | 4 ++++ docs/sources/use/index.rst | 4 ++-- docs/sources/use/puppet.rst | 3 +++ docs/sources/use/workingwithrepository.rst | 4 ++++ docs/theme/docker/layout.html | 2 +- 53 files changed, 185 insertions(+), 19 deletions(-) diff --git a/docs/sources/api/docker_remote_api.rst b/docs/sources/api/docker_remote_api.rst index 2b1aad0e8..1f3861ccb 100644 --- a/docs/sources/api/docker_remote_api.rst +++ b/docs/sources/api/docker_remote_api.rst @@ -1,3 +1,7 @@ +:title: Remote API +:description: API Documentation for Docker +:keywords: API, Docker, rcli, REST, documentation + ================= Docker Remote API ================= diff --git a/docs/sources/api/index.rst b/docs/sources/api/index.rst index 8c118bcbc..4d8ff3fe6 100644 --- a/docs/sources/api/index.rst +++ b/docs/sources/api/index.rst @@ -1,6 +1,6 @@ -:title: docker documentation +:title: API Documentation :description: docker documentation -:keywords: +:keywords: docker, ipa, documentation API's ============= diff --git a/docs/sources/api/registry_api.rst b/docs/sources/api/registry_api.rst index e299584e1..f33ca187b 100644 --- a/docs/sources/api/registry_api.rst +++ b/docs/sources/api/registry_api.rst @@ -1,4 +1,4 @@ -:title: docker Registry documentation +:title: Registry Documentation :description: Documentation for docker Registry and Registry API :keywords: docker, registry, api, index diff --git a/docs/sources/commandline/command/attach.rst b/docs/sources/commandline/command/attach.rst index ac9a84c0c..4c4c189d8 100644 --- a/docs/sources/commandline/command/attach.rst +++ b/docs/sources/commandline/command/attach.rst @@ -1,3 +1,7 @@ +:title: Attach Command +:description: Attach to a running container +:keywords: attach, container, docker, documentation + =========================================== ``attach`` -- Attach to a running container =========================================== diff --git a/docs/sources/commandline/command/build.rst b/docs/sources/commandline/command/build.rst index 8d07c725c..a8d2093a5 100644 --- a/docs/sources/commandline/command/build.rst +++ b/docs/sources/commandline/command/build.rst @@ -1,3 +1,7 @@ +:title: Build Command +:description: Build a new image from the Dockerfile passed via stdin +:keywords: build, docker, container, documentation + ======================================================== ``build`` -- Build a container from Dockerfile via stdin ======================================================== diff --git a/docs/sources/commandline/command/commit.rst b/docs/sources/commandline/command/commit.rst index 1d5c50341..92f320566 100644 --- a/docs/sources/commandline/command/commit.rst +++ b/docs/sources/commandline/command/commit.rst @@ -1,3 +1,7 @@ +:title: Commit Command +:description: Create a new image from a container's changes +:keywords: commit, docker, container, documentation + =========================================================== ``commit`` -- Create a new image from a container's changes =========================================================== diff --git a/docs/sources/commandline/command/diff.rst b/docs/sources/commandline/command/diff.rst index 301da6c49..2901a7f21 100644 --- a/docs/sources/commandline/command/diff.rst +++ b/docs/sources/commandline/command/diff.rst @@ -1,3 +1,7 @@ +:title: Diff Command +:description: Inspect changes on a container's filesystem +:keywords: diff, docker, container, documentation + ======================================================= ``diff`` -- Inspect changes on a container's filesystem ======================================================= diff --git a/docs/sources/commandline/command/export.rst b/docs/sources/commandline/command/export.rst index 88ecd2fd5..9d7e6b369 100644 --- a/docs/sources/commandline/command/export.rst +++ b/docs/sources/commandline/command/export.rst @@ -1,3 +1,7 @@ +:title: Export Command +:description: Export the contents of a filesystem as a tar archive +:keywords: export, docker, container, documentation + ================================================================= ``export`` -- Stream the contents of a container as a tar archive ================================================================= diff --git a/docs/sources/commandline/command/history.rst b/docs/sources/commandline/command/history.rst index 92fad3b48..2f9d3f281 100644 --- a/docs/sources/commandline/command/history.rst +++ b/docs/sources/commandline/command/history.rst @@ -1,3 +1,7 @@ +:title: History Command +:description: Show the history of an image +:keywords: history, docker, container, documentation + =========================================== ``history`` -- Show the history of an image =========================================== diff --git a/docs/sources/commandline/command/images.rst b/docs/sources/commandline/command/images.rst index 5bcfe817f..497bda6e1 100644 --- a/docs/sources/commandline/command/images.rst +++ b/docs/sources/commandline/command/images.rst @@ -1,3 +1,7 @@ +:title: Images Command +:description: List images +:keywords: images, docker, container, documentation + ========================= ``images`` -- List images ========================= diff --git a/docs/sources/commandline/command/import.rst b/docs/sources/commandline/command/import.rst index 5fe90764b..34a7138e0 100644 --- a/docs/sources/commandline/command/import.rst +++ b/docs/sources/commandline/command/import.rst @@ -1,3 +1,7 @@ +:title: Import Command +:description: Create a new filesystem image from the contents of a tarball +:keywords: import, tarball, docker, url, documentation + ========================================================================== ``import`` -- Create a new filesystem image from the contents of a tarball ========================================================================== diff --git a/docs/sources/commandline/command/info.rst b/docs/sources/commandline/command/info.rst index 10697dba1..6df3486c5 100644 --- a/docs/sources/commandline/command/info.rst +++ b/docs/sources/commandline/command/info.rst @@ -1,3 +1,7 @@ +:title: Info Command +:description: Display system-wide information. +:keywords: info, docker, information, documentation + =========================================== ``info`` -- Display system-wide information =========================================== diff --git a/docs/sources/commandline/command/inspect.rst b/docs/sources/commandline/command/inspect.rst index 34365d1f2..90dbe959e 100644 --- a/docs/sources/commandline/command/inspect.rst +++ b/docs/sources/commandline/command/inspect.rst @@ -1,3 +1,7 @@ +:title: Inspect Command +:description: Return low-level information on a container +:keywords: inspect, container, docker, documentation + ========================================================== ``inspect`` -- Return low-level information on a container ========================================================== diff --git a/docs/sources/commandline/command/kill.rst b/docs/sources/commandline/command/kill.rst index cbd019e1a..f53d3883b 100644 --- a/docs/sources/commandline/command/kill.rst +++ b/docs/sources/commandline/command/kill.rst @@ -1,3 +1,7 @@ +:title: Kill Command +:description: Kill a running container +:keywords: kill, container, docker, documentation + ==================================== ``kill`` -- Kill a running container ==================================== diff --git a/docs/sources/commandline/command/login.rst b/docs/sources/commandline/command/login.rst index b064b4014..bab4fa34e 100644 --- a/docs/sources/commandline/command/login.rst +++ b/docs/sources/commandline/command/login.rst @@ -1,3 +1,7 @@ +:title: Login Command +:description: Register or Login to the docker registry server +:keywords: login, docker, documentation + ============================================================ ``login`` -- Register or Login to the docker registry server ============================================================ diff --git a/docs/sources/commandline/command/logs.rst b/docs/sources/commandline/command/logs.rst index 87f3f95b6..a3423f6e0 100644 --- a/docs/sources/commandline/command/logs.rst +++ b/docs/sources/commandline/command/logs.rst @@ -1,3 +1,7 @@ +:title: Logs Command +:description: Fetch the logs of a container +:keywords: logs, container, docker, documentation + ========================================= ``logs`` -- Fetch the logs of a container ========================================= diff --git a/docs/sources/commandline/command/port.rst b/docs/sources/commandline/command/port.rst index 4fb6d7f81..8d59fedab 100644 --- a/docs/sources/commandline/command/port.rst +++ b/docs/sources/commandline/command/port.rst @@ -1,3 +1,7 @@ +:title: Port Command +:description: Lookup the public-facing port which is NAT-ed to PRIVATE_PORT +:keywords: port, docker, container, documentation + ========================================================================= ``port`` -- Lookup the public-facing port which is NAT-ed to PRIVATE_PORT ========================================================================= diff --git a/docs/sources/commandline/command/ps.rst b/docs/sources/commandline/command/ps.rst index f73177918..597dbd9ae 100644 --- a/docs/sources/commandline/command/ps.rst +++ b/docs/sources/commandline/command/ps.rst @@ -1,3 +1,7 @@ +:title: Ps Command +:description: List containers +:keywords: ps, docker, documentation, container + ========================= ``ps`` -- List containers ========================= diff --git a/docs/sources/commandline/command/pull.rst b/docs/sources/commandline/command/pull.rst index 1c417ddcd..4348f28d0 100644 --- a/docs/sources/commandline/command/pull.rst +++ b/docs/sources/commandline/command/pull.rst @@ -1,3 +1,7 @@ +:title: Pull Command +:description: Pull an image or a repository from the registry +:keywords: pull, image, repo, repository, documentation, docker + ========================================================================= ``pull`` -- Pull an image or a repository from the docker registry server ========================================================================= diff --git a/docs/sources/commandline/command/push.rst b/docs/sources/commandline/command/push.rst index a42296c71..9304f9acc 100644 --- a/docs/sources/commandline/command/push.rst +++ b/docs/sources/commandline/command/push.rst @@ -1,3 +1,7 @@ +:title: Push Command +:description: Push an image or a repository to the registry +:keywords: push, docker, image, repository, documentation, repo + ======================================================================= ``push`` -- Push an image or a repository to the docker registry server ======================================================================= diff --git a/docs/sources/commandline/command/restart.rst b/docs/sources/commandline/command/restart.rst index 24bba5a5a..dfc0dfea6 100644 --- a/docs/sources/commandline/command/restart.rst +++ b/docs/sources/commandline/command/restart.rst @@ -1,3 +1,7 @@ +:title: Restart Command +:description: Restart a running container +:keywords: restart, container, docker, documentation + ========================================== ``restart`` -- Restart a running container ========================================== diff --git a/docs/sources/commandline/command/rm.rst b/docs/sources/commandline/command/rm.rst index f6d6893bf..dc6d91632 100644 --- a/docs/sources/commandline/command/rm.rst +++ b/docs/sources/commandline/command/rm.rst @@ -1,3 +1,7 @@ +:title: Rm Command +:description: Remove a container +:keywords: remove, container, docker, documentation, rm + ============================ ``rm`` -- Remove a container ============================ diff --git a/docs/sources/commandline/command/rmi.rst b/docs/sources/commandline/command/rmi.rst index 3761196f2..a0131886d 100644 --- a/docs/sources/commandline/command/rmi.rst +++ b/docs/sources/commandline/command/rmi.rst @@ -1,3 +1,7 @@ +:title: Rmi Command +:description: Remove an image +:keywords: rmi, remove, image, docker, documentation + ========================== ``rmi`` -- Remove an image ========================== diff --git a/docs/sources/commandline/command/run.rst b/docs/sources/commandline/command/run.rst index 95fb208dd..f9bd568b6 100644 --- a/docs/sources/commandline/command/run.rst +++ b/docs/sources/commandline/command/run.rst @@ -1,3 +1,7 @@ +:title: Run Command +:description: Run a command in a new container +:keywords: run, container, docker, documentation + =========================================== ``run`` -- Run a command in a new container =========================================== diff --git a/docs/sources/commandline/command/search.rst b/docs/sources/commandline/command/search.rst index 0af24dfaf..2f07e20c3 100644 --- a/docs/sources/commandline/command/search.rst +++ b/docs/sources/commandline/command/search.rst @@ -1,3 +1,7 @@ +:title: Search Command +:description: Searches for the TERM parameter on the Docker index and prints out a list of repositories that match. +:keywords: search, docker, image, documentation + =================================================================== ``search`` -- Search for an image in the docker index =================================================================== diff --git a/docs/sources/commandline/command/start.rst b/docs/sources/commandline/command/start.rst index df415ca3d..b70ad21cf 100644 --- a/docs/sources/commandline/command/start.rst +++ b/docs/sources/commandline/command/start.rst @@ -1,3 +1,7 @@ +:title: Start Command +:description: Start a stopped container +:keywords: start, docker, container, documentation + ====================================== ``start`` -- Start a stopped container ====================================== diff --git a/docs/sources/commandline/command/stop.rst b/docs/sources/commandline/command/stop.rst index df6d66ccf..3d571563e 100644 --- a/docs/sources/commandline/command/stop.rst +++ b/docs/sources/commandline/command/stop.rst @@ -1,3 +1,7 @@ +:title: Stop Command +:description: Stop a running container +:keywords: stop, container, docker, documentation + ==================================== ``stop`` -- Stop a running container ==================================== diff --git a/docs/sources/commandline/command/tag.rst b/docs/sources/commandline/command/tag.rst index 59647355e..a9e831aae 100644 --- a/docs/sources/commandline/command/tag.rst +++ b/docs/sources/commandline/command/tag.rst @@ -1,3 +1,7 @@ +:title: Tag Command +:description: Tag an image into a repository +:keywords: tag, docker, image, repository, documentation, repo + ========================================= ``tag`` -- Tag an image into a repository ========================================= diff --git a/docs/sources/commandline/command/version.rst b/docs/sources/commandline/command/version.rst index eedf02f2d..fb3d3b450 100644 --- a/docs/sources/commandline/command/version.rst +++ b/docs/sources/commandline/command/version.rst @@ -1,3 +1,7 @@ +:title: Version Command +:description: +:keywords: version, docker, documentation + ================================================== ``version`` -- Show the docker version information ================================================== diff --git a/docs/sources/commandline/command/wait.rst b/docs/sources/commandline/command/wait.rst index 2959bf880..23bd54513 100644 --- a/docs/sources/commandline/command/wait.rst +++ b/docs/sources/commandline/command/wait.rst @@ -1,3 +1,7 @@ +:title: Wait Command +:description: Block until a container stops, then print its exit code. +:keywords: wait, docker, container, documentation + =================================================================== ``wait`` -- Block until a container stops, then print its exit code =================================================================== diff --git a/docs/sources/commandline/index.rst b/docs/sources/commandline/index.rst index fecf8e488..f1a3e2da4 100644 --- a/docs/sources/commandline/index.rst +++ b/docs/sources/commandline/index.rst @@ -1,6 +1,6 @@ -:title: docker documentation +:title: Commands :description: -- todo: change me -:keywords: todo: change me +:keywords: todo, commands, command line, help, docker, documentation Commands diff --git a/docs/sources/concepts/buildingblocks.rst b/docs/sources/concepts/buildingblocks.rst index 154ef00f4..5f752ea47 100644 --- a/docs/sources/concepts/buildingblocks.rst +++ b/docs/sources/concepts/buildingblocks.rst @@ -1,4 +1,4 @@ -:title: Building blocks +:title: Building Blocks :description: An introduction to docker and standard containers? :keywords: containers, lxc, concepts, explanation diff --git a/docs/sources/concepts/containers.rst b/docs/sources/concepts/containers.rst index 8378a7e29..e08c3654c 100644 --- a/docs/sources/concepts/containers.rst +++ b/docs/sources/concepts/containers.rst @@ -1,6 +1,6 @@ :title: Introduction :description: An introduction to docker and standard containers? -:keywords: containers, lxc, concepts, explanation +:keywords: containers, lxc, concepts, explanation, docker, documentation :note: This version of the introduction is temporary, just to make sure we don't break the links from the website when the documentation is updated diff --git a/docs/sources/concepts/index.rst b/docs/sources/concepts/index.rst index d8e1af577..ba1f9f471 100644 --- a/docs/sources/concepts/index.rst +++ b/docs/sources/concepts/index.rst @@ -1,6 +1,6 @@ -:title: docker documentation +:title: Concepts :description: -- todo: change me -:keywords: todo: change me +:keywords: concepts, documentation, docker, containers diff --git a/docs/sources/contributing/contributing.rst b/docs/sources/contributing/contributing.rst index 7b2b4da2d..c2bd7c80f 100644 --- a/docs/sources/contributing/contributing.rst +++ b/docs/sources/contributing/contributing.rst @@ -1,3 +1,7 @@ +:title: Contribution Guidelines +:description: Contribution guidelines: create issues, convetions, pull requests +:keywords: contributing, docker, documentation, help, guideline + Contributing to Docker ====================== diff --git a/docs/sources/faq.rst b/docs/sources/faq.rst index b96ed0643..901e51ddb 100644 --- a/docs/sources/faq.rst +++ b/docs/sources/faq.rst @@ -1,3 +1,7 @@ +:title: FAQ +:description: Most frequently asked questions. +:keywords: faq, questions, documentation, docker + FAQ === diff --git a/docs/sources/index/variable.rst b/docs/sources/index/variable.rst index efbcfae80..90eac3af8 100644 --- a/docs/sources/index/variable.rst +++ b/docs/sources/index/variable.rst @@ -1,3 +1,7 @@ +:title: Index Environment Variable +:description: Setting this environment variable on the docker server will change the URL docker index. +:keywords: docker, index environment variable, documentation + ================================= Docker Index Environment Variable ================================= diff --git a/docs/sources/installation/amazon.rst b/docs/sources/installation/amazon.rst index 64ff20f8b..59896bb63 100644 --- a/docs/sources/installation/amazon.rst +++ b/docs/sources/installation/amazon.rst @@ -1,3 +1,7 @@ +:title: Installation on Amazon EC2 +:description: Docker installation on Amazon EC2 with a single vagrant command. Vagrant 1.1 or higher is required. +:keywords: amazon ec2, virtualization, cloud, docker, documentation, installation + Amazon EC2 ========== diff --git a/docs/sources/installation/archlinux.rst b/docs/sources/installation/archlinux.rst index db013c6cb..9e3766eb2 100644 --- a/docs/sources/installation/archlinux.rst +++ b/docs/sources/installation/archlinux.rst @@ -1,3 +1,7 @@ +:title: Installation on Arch Linux +:description: Docker installation on Arch Linux. +:keywords: arch linux, virtualization, docker, documentation, installation + .. _arch_linux: Arch Linux diff --git a/docs/sources/installation/binaries.rst b/docs/sources/installation/binaries.rst index 25d13ab68..8bab5695c 100644 --- a/docs/sources/installation/binaries.rst +++ b/docs/sources/installation/binaries.rst @@ -1,3 +1,7 @@ +:title: Installation from Binaries +:description: This instruction set is meant for hackers who want to try out Docker on a variety of environments. +:keywords: binaries, installation, docker, documentation, linux + .. _binaries: Binaries diff --git a/docs/sources/installation/index.rst b/docs/sources/installation/index.rst index 1976f30ba..9f831091c 100644 --- a/docs/sources/installation/index.rst +++ b/docs/sources/installation/index.rst @@ -1,6 +1,6 @@ -:title: docker documentation +:title: Documentation :description: -- todo: change me -:keywords: todo: change me +:keywords: todo, docker, documentation, installation, OS support diff --git a/docs/sources/installation/kernel.rst b/docs/sources/installation/kernel.rst index 2ec5940a7..61a7bb385 100644 --- a/docs/sources/installation/kernel.rst +++ b/docs/sources/installation/kernel.rst @@ -1,3 +1,7 @@ +:title: Kernel Requirements +:description: Kernel supports +:keywords: kernel requirements, kernel support, docker, installation, cgroups, namespaces + .. _kernel: Kernel Requirements diff --git a/docs/sources/installation/rackspace.rst b/docs/sources/installation/rackspace.rst index dfb88aee8..748240468 100644 --- a/docs/sources/installation/rackspace.rst +++ b/docs/sources/installation/rackspace.rst @@ -1,3 +1,7 @@ +:title: Rackspace Cloud Installation +:description: Installing Docker on Ubuntu proviced by Rackspace +:keywords: Rackspace Cloud, installation, docker, linux, ubuntu + =============== Rackspace Cloud =============== diff --git a/docs/sources/installation/ubuntulinux.rst b/docs/sources/installation/ubuntulinux.rst index de4a2bb9c..6d2d3e671 100644 --- a/docs/sources/installation/ubuntulinux.rst +++ b/docs/sources/installation/ubuntulinux.rst @@ -1,3 +1,7 @@ +:title: Requirements and Installation on Ubuntu Linux +:description: Please note this project is currently under heavy development. It should not be used in production. +:keywords: Docker, Docker documentation, requirements, virtualbox, vagrant, git, ssh, putty, cygwin, linux + .. _ubuntu_linux: Ubuntu Linux diff --git a/docs/sources/installation/upgrading.rst b/docs/sources/installation/upgrading.rst index 8dfde7389..9fa47904b 100644 --- a/docs/sources/installation/upgrading.rst +++ b/docs/sources/installation/upgrading.rst @@ -1,3 +1,7 @@ +:title: Upgrading +:description: These instructions are for upgrading Docker +:keywords: Docker, Docker documentation, upgrading docker, upgrade + .. _upgrading: Upgrading diff --git a/docs/sources/installation/vagrant.rst b/docs/sources/installation/vagrant.rst index d1a76b5a2..24a1e9135 100644 --- a/docs/sources/installation/vagrant.rst +++ b/docs/sources/installation/vagrant.rst @@ -1,3 +1,6 @@ +:title: Using Vagrant (Mac, Linux) +:description: This guide will setup a new virtualbox virtual machine with docker installed on your computer. +:keywords: Docker, Docker documentation, virtualbox, vagrant, git, ssh, putty, cygwin .. _install_using_vagrant: diff --git a/docs/sources/toctree.rst b/docs/sources/toctree.rst index 09f2a7af5..ae6d5f010 100644 --- a/docs/sources/toctree.rst +++ b/docs/sources/toctree.rst @@ -1,6 +1,6 @@ -:title: docker documentation -:description: docker documentation -:keywords: +:title: Documentation +:description: -- todo: change me +:keywords: todo, docker, documentation, installation, usage, examples, contributing, faq, command line, concepts Documentation ============= diff --git a/docs/sources/use/basics.rst b/docs/sources/use/basics.rst index ffd2a7b96..6ae0711f1 100644 --- a/docs/sources/use/basics.rst +++ b/docs/sources/use/basics.rst @@ -1,6 +1,6 @@ -:title: Base commands +:title: Basic Commands :description: Common usage and commands -:keywords: Examples, Usage +:keywords: Examples, Usage, basic commands, docker, documentation, examples The basics diff --git a/docs/sources/use/builder.rst b/docs/sources/use/builder.rst index 735b2e575..07856febe 100644 --- a/docs/sources/use/builder.rst +++ b/docs/sources/use/builder.rst @@ -1,3 +1,7 @@ +:title: Docker Builder +:description: Docker Builder specifes a simple DSL which allows you to automate the steps you would normally manually take to create an image. +:keywords: builder, docker, Docker Builder, automation, image creation + ============== Docker Builder ============== diff --git a/docs/sources/use/index.rst b/docs/sources/use/index.rst index 9939dc7ea..a1086c1fd 100644 --- a/docs/sources/use/index.rst +++ b/docs/sources/use/index.rst @@ -1,6 +1,6 @@ -:title: docker documentation +:title: Documentation :description: -- todo: change me -:keywords: todo: change me +:keywords: todo, docker, documentation, basic, builder diff --git a/docs/sources/use/puppet.rst b/docs/sources/use/puppet.rst index af2d5c8d5..1c48aec8e 100644 --- a/docs/sources/use/puppet.rst +++ b/docs/sources/use/puppet.rst @@ -1,3 +1,6 @@ +:title: Puppet Usage +:description: Installating and using Puppet +:keywords: puppet, installation, usage, docker, documentation .. _install_using_puppet: diff --git a/docs/sources/use/workingwithrepository.rst b/docs/sources/use/workingwithrepository.rst index c1ce7f455..9a2f96cf0 100644 --- a/docs/sources/use/workingwithrepository.rst +++ b/docs/sources/use/workingwithrepository.rst @@ -1,3 +1,7 @@ +:title: Working With Repositories +:description: Generally, there are two types of repositories: Top-level repositories which are controlled by the people behind Docker, and user repositories. +:keywords: repo, repositiores, usage, pull image, push image, image, documentation + .. _working_with_the_repository: Working with the repository diff --git a/docs/theme/docker/layout.html b/docs/theme/docker/layout.html index aa5a24d49..d212c9ca8 100755 --- a/docs/theme/docker/layout.html +++ b/docs/theme/docker/layout.html @@ -8,7 +8,7 @@ - Docker - {{ meta['title'] if meta and meta['title'] else title }} + {{ meta['title'] if meta and meta['title'] else title }} - Docker Documentation From 0f135ad7f31df2952352feb9ef00863d61577467 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Wed, 22 May 2013 20:07:26 -0700 Subject: [PATCH 38/95] Start moving the docker builder into the server --- api.go | 80 ++++++++++++++++++++++++++++++++++++++++++++++- builder_client.go | 35 +++++++++++++-------- commands.go | 50 +++++++++++++++++++++++++++-- server.go | 16 +++++----- 4 files changed, 157 insertions(+), 24 deletions(-) diff --git a/api.go b/api.go index 29103fac1..5812743df 100644 --- a/api.go +++ b/api.go @@ -1,6 +1,7 @@ package docker import ( + "bytes" "encoding/json" "fmt" "github.com/dotcloud/docker/auth" @@ -9,6 +10,7 @@ import ( "io" "log" "net/http" + "os" "strconv" "strings" ) @@ -31,6 +33,13 @@ func parseForm(r *http.Request) error { return nil } +func parseMultipartForm(r *http.Request) error { + if err := r.ParseMultipartForm(4096); err != nil && !strings.HasPrefix(err.Error(), "mime:") { + return err + } + return nil +} + func httpError(w http.ResponseWriter, err error) { if strings.HasPrefix(err.Error(), "No such") { http.Error(w, err.Error(), http.StatusNotFound) @@ -329,9 +338,15 @@ func postImagesInsert(srv *Server, w http.ResponseWriter, r *http.Request, vars } name := vars["name"] - if err := srv.ImageInsert(name, url, path, w); err != nil { + imgId, err := srv.ImageInsert(name, url, path, w) + if err != nil { return err } + b, err := json.Marshal(&ApiId{Id: imgId}) + if err != nil { + return err + } + writeJson(w, b) return nil } @@ -585,6 +600,68 @@ func postImagesGetCache(srv *Server, w http.ResponseWriter, r *http.Request, var return nil } +func Upload(w http.ResponseWriter, req *http.Request) { + + mr, err := req.MultipartReader() + if err != nil { + return + } + length := req.ContentLength + for { + + part, err := mr.NextPart() + if err == io.EOF { + break + } + var read int64 + var p float32 + for { + buffer := make([]byte, 100000) + cBytes, err := part.Read(buffer) + if err == io.EOF { + break + } + read = read + int64(cBytes) + //fmt.Printf("read: %v \n",read ) + p = float32(read) / float32(length) * 100 + fmt.Printf("progress: %v \n", p) + os.Stdout.Write(buffer) + } + } +} + +func postBuild(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { + + Upload(w, r) + + // io.Copy(os.Stderr, r.Body) + + if err := r.ParseMultipartForm(409699); err != nil { + utils.Debugf("----- %s\n", err) + return err + } + + mpr, err := r.MultipartReader() + if err != nil { + return err + } + + p, err := mpr.NextPart() + if err != nil { + return err + } + + dockerfile := make([]byte, 4096) + p.Read(dockerfile) + + utils.Debugf("Dockerfile >>>%s<<<\n", dockerfile) + b := NewBuildFile(srv, w) + if _, err := b.Build(bytes.NewReader(dockerfile)); err != nil { + return err + } + return nil +} + func ListenAndServe(addr string, srv *Server, logging bool) error { r := mux.NewRouter() log.Printf("Listening for HTTP on %s\n", addr) @@ -607,6 +684,7 @@ func ListenAndServe(addr string, srv *Server, logging bool) error { "POST": { "/auth": postAuth, "/commit": postCommit, + "/build": postBuild, "/images/create": postImagesCreate, "/images/{name:.*}/insert": postImagesInsert, "/images/{name:.*}/push": postImagesPush, diff --git a/builder_client.go b/builder_client.go index ceeab002c..e0a55ae6c 100644 --- a/builder_client.go +++ b/builder_client.go @@ -12,12 +12,6 @@ import ( "strings" ) -type BuilderClient interface { - Build(io.Reader) (string, error) - CmdFrom(string) error - CmdRun(string) error -} - type builderClient struct { cli *DockerCli @@ -164,8 +158,23 @@ func (b *builderClient) CmdExpose(args string) error { } func (b *builderClient) CmdInsert(args string) error { - // FIXME: Reimplement this once the remove_hijack branch gets merged. - // We need to retrieve the resulting Id + // tmp := strings.SplitN(args, "\t ", 2) + // sourceUrl, destPath := tmp[0], tmp[1] + + // v := url.Values{} + // v.Set("url", sourceUrl) + // v.Set("path", destPath) + // body, _, err := b.cli.call("POST", "/images/insert?"+v.Encode(), nil) + // if err != nil { + // return err + // } + + // apiId := &ApiId{} + // if err := json.Unmarshal(body, apiId); err != nil { + // return err + // } + + // FIXME: Reimplement this, we need to retrieve the resulting Id return fmt.Errorf("INSERT not implemented") } @@ -269,18 +278,18 @@ func (b *builderClient) Build(dockerfile io.Reader) (string, error) { instruction := strings.ToLower(strings.Trim(tmp[0], " ")) arguments := strings.Trim(tmp[1], " ") - fmt.Printf("%s %s (%s)\n", strings.ToUpper(instruction), arguments, b.image) + fmt.Fprintf(os.Stderr, "%s %s (%s)\n", strings.ToUpper(instruction), arguments, b.image) method, exists := reflect.TypeOf(b).MethodByName("Cmd" + strings.ToUpper(instruction[:1]) + strings.ToLower(instruction[1:])) if !exists { - fmt.Printf("Skipping unknown instruction %s\n", strings.ToUpper(instruction)) + fmt.Fprintf(os.Stderr, "Skipping unknown instruction %s\n", strings.ToUpper(instruction)) } ret := method.Func.Call([]reflect.Value{reflect.ValueOf(b), reflect.ValueOf(arguments)})[0].Interface() if ret != nil { return "", ret.(error) } - fmt.Printf("===> %v\n", b.image) + fmt.Fprintf(os.Stderr, "===> %v\n", b.image) } if b.needCommit { if err := b.commit(""); err != nil { @@ -295,13 +304,13 @@ func (b *builderClient) Build(dockerfile io.Reader) (string, error) { for i := range b.tmpContainers { delete(b.tmpContainers, i) } - fmt.Printf("Build finished. image id: %s\n", b.image) + fmt.Fprintf(os.Stderr, "Build finished. image id: %s\n", b.image) return b.image, nil } return "", fmt.Errorf("An error occured during the build\n") } -func NewBuilderClient(addr string, port int) BuilderClient { +func NewBuilderClient(addr string, port int) BuildFile { return &builderClient{ cli: NewDockerCli(addr, port), config: &Config{}, diff --git a/commands.go b/commands.go index 5e459a1d9..4291b1d8d 100644 --- a/commands.go +++ b/commands.go @@ -10,6 +10,7 @@ import ( "github.com/dotcloud/docker/utils" "io" "io/ioutil" + "mime/multipart" "net" "net/http" "net/http/httputil" @@ -104,14 +105,59 @@ func (cli *DockerCli) CmdInsert(args ...string) error { v.Set("url", cmd.Arg(1)) v.Set("path", cmd.Arg(2)) - err := cli.stream("POST", "/images/"+cmd.Arg(0)+"/insert?"+v.Encode(), nil, os.Stdout) - if err != nil { + if err := cli.stream("POST", "/images/"+cmd.Arg(0)+"/insert?"+v.Encode(), nil, os.Stdout); err != nil { return err } return nil } func (cli *DockerCli) CmdBuild(args ...string) error { + + buff := bytes.NewBuffer([]byte{}) + + w := multipart.NewWriter(buff) + + dockerfile, err := w.CreateFormFile("Dockerfile", "Dockerfile") + if err != nil { + return err + } + file, err := os.Open("Dockerfile") + if err != nil { + return err + } + dockerfile.Write([]byte(w.Boundary() + "\r\n")) + if _, err := io.Copy(dockerfile, file); err != nil { + return err + } + dockerfile.Write([]byte("\r\n" + w.Boundary())) + + // req, err := http.NewRequest("POST", fmt.Sprintf("http://%s:%d%s", cli.host, cli.port, "/build"), buff) + // if err != nil { + // return err + // } + // req.Header.Set("Content-Type", w.FormDataContentType()) + resp, err := http.Post(fmt.Sprintf("http://%s:%d%s", cli.host, cli.port, "/build"), w.FormDataContentType(), buff) + if err != nil { + return err + } + defer resp.Body.Close() + + if resp.StatusCode < 200 || resp.StatusCode >= 400 { + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return err + } + return fmt.Errorf("error: %s", body) + } + + if _, err := io.Copy(os.Stdout, resp.Body); err != nil { + return err + } + + return nil +} + +func (cli *DockerCli) CmdBuildClient(args ...string) error { cmd := Subcmd("build", "-|Dockerfile", "Build an image from Dockerfile or via stdin") if err := cmd.Parse(args); err != nil { return nil diff --git a/server.go b/server.go index 564b1c812..06f947d89 100644 --- a/server.go +++ b/server.go @@ -67,40 +67,40 @@ func (srv *Server) ImagesSearch(term string) ([]ApiSearch, error) { return outs, nil } -func (srv *Server) ImageInsert(name, url, path string, out io.Writer) error { +func (srv *Server) ImageInsert(name, url, path string, out io.Writer) (string, error) { out = utils.NewWriteFlusher(out) img, err := srv.runtime.repositories.LookupImage(name) if err != nil { - return err + return "", err } file, err := utils.Download(url, out) if err != nil { - return err + return "", err } defer file.Body.Close() config, _, err := ParseRun([]string{img.Id, "echo", "insert", url, path}, srv.runtime.capabilities) if err != nil { - return err + return "", err } b := NewBuilder(srv.runtime) c, err := b.Create(config) if err != nil { - return err + return "", err } if err := c.Inject(utils.ProgressReader(file.Body, int(file.ContentLength), out, "Downloading %v/%v (%v)"), path); err != nil { - return err + return "", err } // FIXME: Handle custom repo, tag comment, author img, err = b.Commit(c, "", "", img.Comment, img.Author, nil) if err != nil { - return err + return "", err } fmt.Fprintf(out, "%s\n", img.Id) - return nil + return img.ShortId(), nil } func (srv *Server) ImagesViz(out io.Writer) error { From 9e0427081e80dbf6c7702c8428ec64e40f362804 Mon Sep 17 00:00:00 2001 From: Andreas Tiefenthaler Date: Thu, 23 May 2013 18:09:59 +0300 Subject: [PATCH 39/95] Fixing two typos in the run help --- docs/sources/commandline/command/run.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sources/commandline/command/run.rst b/docs/sources/commandline/command/run.rst index f9bd568b6..d6c9aef31 100644 --- a/docs/sources/commandline/command/run.rst +++ b/docs/sources/commandline/command/run.rst @@ -23,5 +23,5 @@ -t=false: Allocate a pseudo-tty -u="": Username or UID -d=[]: Set custom dns servers for the container - -v=[]: Creates a new volumes and mount it at the specified path. + -v=[]: Creates a new volume and mounts it at the specified path. -volumes-from="": Mount all volumes from the given container. From cf35e8ed81029a3c2717659eac7979017bb01890 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 23 May 2013 15:16:35 +0000 Subject: [PATCH 40/95] jsonstream WIP --- api.go | 1 + commands.go | 27 +++++++++++++++++++++++++-- server.go | 15 ++++++--------- utils/utils.go | 11 +++-------- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/api.go b/api.go index 29103fac1..b43a2c7b9 100644 --- a/api.go +++ b/api.go @@ -288,6 +288,7 @@ func postImagesCreate(srv *Server, w http.ResponseWriter, r *http.Request, vars if image != "" { //pull registry := r.Form.Get("registry") + w.Header().Set("Content-Type", "application/json") if err := srv.ImagePull(image, tag, registry, w); err != nil { return err } diff --git a/commands.go b/commands.go index 5e459a1d9..f91ccfc51 100644 --- a/commands.go +++ b/commands.go @@ -1223,8 +1223,31 @@ func (cli *DockerCli) stream(method, path string, in io.Reader, out io.Writer) e return fmt.Errorf("error: %s", body) } - if _, err := io.Copy(out, resp.Body); err != nil { - return err + if resp.Header.Get("Content-Type") == "application/json" { + + type Message struct { + Status string `json:"status,omitempty"` + Progress string `json:"progress,omitempty"` + } + dec := json.NewDecoder(resp.Body) + for { + var m Message + if err := dec.Decode(&m); err == io.EOF { + break + } else if err != nil { + return err + } + if m.Status != "" { + fmt.Fprintf(out, "%s\n", m.Status) + } else if m.Progress != "" { + fmt.Fprintf(out, "Downloading... %s\r", m.Progress) + } + } + fmt.Fprintf(out, "\n") + } else { + if _, err := io.Copy(out, resp.Body); err != nil { + return err + } } return nil } diff --git a/server.go b/server.go index 564b1c812..7919dd43a 100644 --- a/server.go +++ b/server.go @@ -292,17 +292,15 @@ func (srv *Server) ContainerTag(name, repo, tag string, force bool) error { } func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []string) error { - out = utils.NewWriteFlusher(out) history, err := srv.registry.GetRemoteHistory(imgId, registry, token) if err != nil { return err } - // FIXME: Try to stream the images? // FIXME: Launch the getRemoteImage() in goroutines for _, id := range history { if !srv.runtime.graph.Exists(id) { - fmt.Fprintf(out, "Pulling %s metadata\r\n", id) + fmt.Fprintf(out, "{\"status\" :\"Pulling %s metadata\"}", id) imgJson, err := srv.registry.GetRemoteImageJson(id, registry, token) if err != nil { // FIXME: Keep goging in case of error? @@ -314,12 +312,12 @@ func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []stri } // Get the layer - fmt.Fprintf(out, "Pulling %s fs layer\r\n", img.Id) + fmt.Fprintf(out, "{\"status\" :\"Pulling %s fs layer\"}", img.Id) layer, contentLength, err := srv.registry.GetRemoteImageLayer(img.Id, registry, token) if err != nil { return err } - if err := srv.runtime.graph.Register(utils.ProgressReader(layer, contentLength, out, "Downloading %v/%v (%v)"), false, img); err != nil { + if err := srv.runtime.graph.Register(utils.ProgressReader(layer, contentLength, out, ""), false, img); err != nil { return err } } @@ -328,8 +326,7 @@ func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []stri } func (srv *Server) pullRepository(out io.Writer, remote, askedTag string) error { - out = utils.NewWriteFlusher(out) - fmt.Fprintf(out, "Pulling repository %s from %s\r\n", remote, auth.IndexServerAddress()) + fmt.Fprintf(out, "{\"status\":\"Pulling repository %s from %s\"}", remote, auth.IndexServerAddress()) repoData, err := srv.registry.GetRepositoryData(remote) if err != nil { return err @@ -366,7 +363,7 @@ func (srv *Server) pullRepository(out io.Writer, remote, askedTag string) error utils.Debugf("(%s) does not match %s (id: %s), skipping", img.Tag, askedTag, img.Id) continue } - fmt.Fprintf(out, "Pulling image %s (%s) from %s\n", img.Id, img.Tag, remote) + fmt.Fprintf(out, "{\"status\":\"Pulling image %s (%s) from %s\"}", img.Id, img.Tag, remote) success := false for _, ep := range repoData.Endpoints { if err := srv.pullImage(out, img.Id, "https://"+ep+"/v1", repoData.Tokens); err != nil { @@ -396,6 +393,7 @@ func (srv *Server) pullRepository(out io.Writer, remote, askedTag string) error } func (srv *Server) ImagePull(name, tag, registry string, out io.Writer) error { + out = utils.NewWriteFlusher(out) if registry != "" { if err := srv.pullImage(out, name, registry, nil); err != nil { return err @@ -406,7 +404,6 @@ func (srv *Server) ImagePull(name, tag, registry string, out io.Writer) error { if err := srv.pullRepository(out, name, tag); err != nil { return err } - return nil } diff --git a/utils/utils.go b/utils/utils.go index 150eae857..cf807cfa1 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -84,17 +84,12 @@ func (r *progressReader) Read(p []byte) (n int, err error) { } if r.readProgress-r.lastUpdate > updateEvery || err != nil { if r.readTotal > 0 { - fmt.Fprintf(r.output, r.template+"\r", r.readProgress, r.readTotal, fmt.Sprintf("%.0f%%", float64(r.readProgress)/float64(r.readTotal)*100)) + fmt.Fprintf(r.output, r.template, r.readProgress, r.readTotal) } else { - fmt.Fprintf(r.output, r.template+"\r", r.readProgress, "?", "n/a") + fmt.Fprintf(r.output, r.template, r.readProgress, "?") } r.lastUpdate = r.readProgress } - // Send newline when complete - if err != nil { - fmt.Fprintf(r.output, "\n") - } - return read, err } func (r *progressReader) Close() error { @@ -102,7 +97,7 @@ func (r *progressReader) Close() error { } func ProgressReader(r io.ReadCloser, size int, output io.Writer, template string) *progressReader { if template == "" { - template = "%v/%v (%v)" + template = "{\"progress\":\"%v/%v\"}" } return &progressReader{r, NewWriteFlusher(output), size, 0, 0, template} } From e77263010ce882790f12dfcd0841ea784dab0738 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Thu, 23 May 2013 09:47:20 -0600 Subject: [PATCH 41/95] Simplified and clarified kernel install instructions --- docs/sources/installation/kernel.rst | 61 +++++----------------------- 1 file changed, 11 insertions(+), 50 deletions(-) diff --git a/docs/sources/installation/kernel.rst b/docs/sources/installation/kernel.rst index 61a7bb385..6331a7734 100644 --- a/docs/sources/installation/kernel.rst +++ b/docs/sources/installation/kernel.rst @@ -7,20 +7,25 @@ Kernel Requirements =================== +In short, Docker has the following kernel requirements: + +- Linux version 3.8 or above. + +- Compiled with `AUFS support `_. + +- Cgroups and namespaces must be enabled. + + The officially supported kernel is the one recommended by the :ref:`ubuntu_linux` installation path. It is the one that most developers will use, and the one that receives the most attention from the core contributors. If you decide to go with a different kernel and hit a bug, please try to reproduce it with the official kernels first. -If for some reason you cannot or do not want to use the "official" kernels, +If you cannot or do not want to use the "official" kernels, here is some technical background about the features (both optional and mandatory) that docker needs to run successfully. -In short, you need kernel version 3.8 (or above), compiled to include -`AUFS support `_. Of course, you need to -enable cgroups and namespaces. - Namespaces and Cgroups ---------------------- @@ -38,30 +43,11 @@ Kernels 2.6.38, and every version since 3.2, have been deployed successfully to run containerized production workloads. Feature-wise, there is no huge improvement between 2.6.38 and up to 3.6 (as far as docker is concerned!). -Starting with version 3.7, the kernel has basic support for -`Checkpoint/Restore In Userspace `_, which is not used by -docker at this point, but allows to suspend the state of a container to -disk and resume it later. - -Version 3.8 provides improvements in stability, which are deemed necessary -for the operation of docker. Versions 3.2 to 3.5 have been shown to -exhibit a reproducible bug (for more details, see issue -`#407 `_). - -Version 3.8 also brings better support for the -`setns() syscall `_ -- but this should not -be a concern since docker does not leverage on this feature for now. - -If you want a technical overview about those concepts, you might -want to check those articles on dotCloud's blog: -`about namespaces `_ -and `about cgroups `_. - Important Note About Pre-3.8 Kernels ------------------------------------ -As mentioned above, kernels before 3.8 are not stable when used with docker. +Kernel versions 3.2 to 3.5 are not stable when used with docker. In some circumstances, you will experience kernel "oopses", or even crashes. The symptoms include: @@ -126,28 +112,3 @@ distributions, is not part of the standard kernel. This means that if you decide to roll your own kernel, you will have to patch your kernel tree to add AUFS. The process is documented on `AUFS webpage `_. - -Note: the AUFS patch is fairly intrusive, but for the record, people have -successfully applied GRSEC and AUFS together, to obtain hardened production -kernels. - -If you want more information about that topic, there is an -`article about AUFS on dotCloud's blog -`_. - - -BTRFS, ZFS, OverlayFS... ------------------------- - -There is ongoing development on docker, to implement support for -`BTRFS `_ -(see github issue `#443 `_). - -People have also showed interest for `ZFS `_ -(using e.g. `ZFS-on-Linux `_) and OverlayFS. -The latter is functionally close to AUFS, and it might end up being included -in the stock kernel; so it's a strong candidate! - -Would you like to `contribute -`_ -support for your favorite filesystem? From dbb7b60cfc97dc1b7a1412775475048b6bf18e67 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Thu, 23 May 2013 09:49:53 -0600 Subject: [PATCH 42/95] Re-ordered and re-titled kernel requirement details to match the shortlist --- docs/sources/installation/kernel.rst | 65 ++++++++++++++-------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/docs/sources/installation/kernel.rst b/docs/sources/installation/kernel.rst index 6331a7734..6f242e9e1 100644 --- a/docs/sources/installation/kernel.rst +++ b/docs/sources/installation/kernel.rst @@ -11,7 +11,7 @@ In short, Docker has the following kernel requirements: - Linux version 3.8 or above. -- Compiled with `AUFS support `_. +- `AUFS support `_. - Cgroups and namespaces must be enabled. @@ -26,26 +26,8 @@ If you cannot or do not want to use the "official" kernels, here is some technical background about the features (both optional and mandatory) that docker needs to run successfully. - -Namespaces and Cgroups ----------------------- - -You need to enable namespaces and cgroups, to the extend of what is needed -to run LXC containers. Technically, while namespaces have been introduced -in the early 2.6 kernels, we do not advise to try any kernel before 2.6.32 -to run LXC containers. Note that 2.6.32 has some documented issues regarding -network namespace setup and teardown; those issues are not a risk if you -run containers in a private environment, but can lead to denial-of-service -attacks if you want to run untrusted code in your containers. For more details, -see `[LP#720095 `_. - -Kernels 2.6.38, and every version since 3.2, have been deployed successfully -to run containerized production workloads. Feature-wise, there is no huge -improvement between 2.6.38 and up to 3.6 (as far as docker is concerned!). - - -Important Note About Pre-3.8 Kernels ------------------------------------- +Linux version 3.8 or above +-------------------------- Kernel versions 3.2 to 3.5 are not stable when used with docker. In some circumstances, you will experience kernel "oopses", or even crashes. @@ -67,6 +49,36 @@ detects something older than 3.8. See issue `#407 `_ for details. +AUFS support +------------ + +Docker currently relies on AUFS, an unioning filesystem. +While AUFS is included in the kernels built by the Debian and Ubuntu +distributions, is not part of the standard kernel. This means that if +you decide to roll your own kernel, you will have to patch your +kernel tree to add AUFS. The process is documented on +`AUFS webpage `_. + + +Cgroups and namespaces +---------------------- + +You need to enable namespaces and cgroups, to the extend of what is needed +to run LXC containers. Technically, while namespaces have been introduced +in the early 2.6 kernels, we do not advise to try any kernel before 2.6.32 +to run LXC containers. Note that 2.6.32 has some documented issues regarding +network namespace setup and teardown; those issues are not a risk if you +run containers in a private environment, but can lead to denial-of-service +attacks if you want to run untrusted code in your containers. For more details, +see `[LP#720095 `_. + +Kernels 2.6.38, and every version since 3.2, have been deployed successfully +to run containerized production workloads. Feature-wise, there is no huge +improvement between 2.6.38 and up to 3.6 (as far as docker is concerned!). + + + + Extra Cgroup Controllers ------------------------ @@ -101,14 +113,3 @@ And replace it by the following one:: GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount" Then run ``update-grub``, and reboot. - - -AUFS ----- - -Docker currently relies on AUFS, an unioning filesystem. -While AUFS is included in the kernels built by the Debian and Ubuntu -distributions, is not part of the standard kernel. This means that if -you decide to roll your own kernel, you will have to patch your -kernel tree to add AUFS. The process is documented on -`AUFS webpage `_. From 13f1939a6316079c14bac5434ecc2c955af1d1fb Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 23 May 2013 16:09:28 +0000 Subject: [PATCH 43/95] switch to default 127.0.0.1, and mixed the two flags in one. -h --- commands.go | 18 +++++++++--------- docker/docker.go | 27 +++++++++++++++++++++------ docs/sources/commandline/cli.rst | 3 +-- docs/sources/use/basics.rst | 4 ++-- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/commands.go b/commands.go index 50f8533a2..fda90489e 100644 --- a/commands.go +++ b/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/docker/docker.go b/docker/docker.go index 800c8f09c..37a0578d5 100644 --- a/docker/docker.go +++ b/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/docs/sources/commandline/cli.rst b/docs/sources/commandline/cli.rst index 8ea3d1935..3bb904b46 100644 --- a/docs/sources/commandline/cli.rst +++ b/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/docs/sources/use/basics.rst b/docs/sources/use/basics.rst index 9a5f8faf4..c71147e3f 100644 --- a/docs/sources/use/basics.rst +++ b/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 59835135c572db08798dde7a5e211e7f4b453742 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 23 May 2013 16:15:36 +0000 Subject: [PATCH 44/95] added warning --- docker/docker.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker/docker.go b/docker/docker.go index 37a0578d5..f2dca2de1 100644 --- a/docker/docker.go +++ b/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 31c98bdaafd806d7c5e44f2ed25cf57e7ef20827 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 23 May 2013 16:32:39 +0000 Subject: [PATCH 45/95] 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 --- commands.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/commands.go b/commands.go index 5e459a1d9..16dfdbfc2 100644 --- a/commands.go +++ b/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 e0e385ac696c339958cdb9b4094c25f120dae1ec Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Thu, 23 May 2013 11:12:54 -0600 Subject: [PATCH 46/95] * Build: leave temporary containers untouched after a failure to help debugging --- builder_client.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/builder_client.go b/builder_client.go index ceeab002c..c3950b2be 100644 --- a/builder_client.go +++ b/builder_client.go @@ -32,12 +32,6 @@ type builderClient struct { } func (b *builderClient) clearTmp(containers, images map[string]struct{}) { - for c := range containers { - if _, _, err := b.cli.call("DELETE", "/containers/"+c, nil); err != nil { - utils.Debugf("%s", err) - } - utils.Debugf("Removing container %s", c) - } for i := range images { if _, _, err := b.cli.call("DELETE", "/images/"+i, nil); err != nil { utils.Debugf("%s", err) From d17c0b83681d45f4b4c57ca66cfc574246fd6618 Mon Sep 17 00:00:00 2001 From: Daniel Mizyrycki Date: Thu, 23 May 2013 12:42:58 -0700 Subject: [PATCH 47/95] Packaging: Update changelog for release 0.3.3 --- CHANGELOG.md | 4 +++ packaging/ubuntu/changelog | 63 +++++++++++++++++++++----------------- 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9e2dab79..4d3502d23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.3.3 (2013-05-23) + - Registry: Fix push regression + - Various bugfixes + ## 0.3.2 (2013-05-09) * Runtime: Store the actual archive on commit * Registry: Improve the checksum process diff --git a/packaging/ubuntu/changelog b/packaging/ubuntu/changelog index 2e4907f20..c8a8c1689 100644 --- a/packaging/ubuntu/changelog +++ b/packaging/ubuntu/changelog @@ -1,37 +1,44 @@ +lxc-docker (0.3.3-1) precise; urgency=low + - Registry: Fix push regression + - Various bugfixes + + -- dotCloud Thu, 23 May 2013 00:00:00 -0700 + + lxc-docker (0.3.2-1) precise; urgency=low - - Runtime: Store the actual archive on commit - - Registry: Improve the checksum process - - Registry: Use the size to have a good progress bar while pushing - - Registry: Use the actual archive if it exists in order to speed up the push - - Registry: Fix error 400 on push + - Runtime: Store the actual archive on commit + - Registry: Improve the checksum process + - Registry: Use the size to have a good progress bar while pushing + - Registry: Use the actual archive if it exists in order to speed up the push + - Registry: Fix error 400 on push -- dotCloud Fri, 9 May 2013 00:00:00 -0700 lxc-docker (0.3.1-1) precise; urgency=low - - Builder: Implement the autorun capability within docker builder - - Builder: Add caching to docker builder - - Builder: Add support for docker builder with native API as top level command - - Runtime: Add go version to debug infos - - Builder: Implement ENV within docker builder - - Registry: Add docker search top level command in order to search a repository - - Images: output graph of images to dot (graphviz) - - Documentation: new introduction and high-level overview - - Documentation: Add the documentation for docker builder - - Website: new high-level overview - - Makefile: Swap "go get" for "go get -d", especially to compile on go1.1rc - - Images: fix ByParent function - - Builder: Check the command existance prior create and add Unit tests for the case - - Registry: Fix pull for official images with specific tag - - Registry: Fix issue when login in with a different user and trying to push - - Documentation: CSS fix for docker documentation to make REST API docs look better. - - Documentation: Fixed CouchDB example page header mistake - - Documentation: fixed README formatting - - Registry: Improve checksum - async calculation - - Runtime: kernel version - don't show the dash if flavor is empty - - Documentation: updated www.docker.io website. - - Builder: use any whitespaces instead of tabs - - Packaging: packaging ubuntu; issue #510: Use goland-stable PPA package to build docker + - Builder: Implement the autorun capability within docker builder + - Builder: Add caching to docker builder + - Builder: Add support for docker builder with native API as top level command + - Runtime: Add go version to debug infos + - Builder: Implement ENV within docker builder + - Registry: Add docker search top level command in order to search a repository + - Images: output graph of images to dot (graphviz) + - Documentation: new introduction and high-level overview + - Documentation: Add the documentation for docker builder + - Website: new high-level overview + - Makefile: Swap "go get" for "go get -d", especially to compile on go1.1rc + - Images: fix ByParent function + - Builder: Check the command existance prior create and add Unit tests for the case + - Registry: Fix pull for official images with specific tag + - Registry: Fix issue when login in with a different user and trying to push + - Documentation: CSS fix for docker documentation to make REST API docs look better. + - Documentation: Fixed CouchDB example page header mistake + - Documentation: fixed README formatting + - Registry: Improve checksum - async calculation + - Runtime: kernel version - don't show the dash if flavor is empty + - Documentation: updated www.docker.io website. + - Builder: use any whitespaces instead of tabs + - Packaging: packaging ubuntu; issue #510: Use goland-stable PPA package to build docker -- dotCloud Fri, 8 May 2013 00:00:00 -0700 From 822056094aa31c224e78cd568e02fe5458a0eecc Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Thu, 23 May 2013 12:46:14 -0700 Subject: [PATCH 48/95] Bumped version to 0.3.3 --- commands.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands.go b/commands.go index 17d7e08ff..75ba562cd 100644 --- a/commands.go +++ b/commands.go @@ -24,7 +24,7 @@ import ( "unicode" ) -const VERSION = "0.3.2" +const VERSION = "0.3.3" var ( GIT_COMMIT string From 83bc5b7435565d227a7745f4832bc9ce6be7a80d Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Thu, 23 May 2013 15:48:50 -0500 Subject: [PATCH 49/95] utils.go: Fix merge logic for user and hostname. Fall back to image-specified hostname if user doesn't provide one, instead of only using image-specified hostname if the user *does* try to set one. (ditto for username) Closes #694. --- utils.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils.go b/utils.go index 27478002d..5a9d02c49 100644 --- a/utils.go +++ b/utils.go @@ -49,10 +49,10 @@ func CompareConfig(a, b *Config) bool { } func MergeConfig(userConf, imageConf *Config) { - if userConf.Hostname != "" { + if userConf.Hostname == "" { userConf.Hostname = imageConf.Hostname } - if userConf.User != "" { + if userConf.User == "" { userConf.User = imageConf.User } if userConf.Memory == 0 { From d42c10aa094e39d8c1184b61c98777d8c59ae900 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Thu, 23 May 2013 18:32:56 -0700 Subject: [PATCH 50/95] Implement Context within docker build (not yet in use) --- api.go | 23 +++++----------- builder_client.go | 2 +- commands.go | 70 ++++++++++++++++++++++++++++++++++------------- 3 files changed, 59 insertions(+), 36 deletions(-) diff --git a/api.go b/api.go index 5812743df..0a65543b7 100644 --- a/api.go +++ b/api.go @@ -1,7 +1,6 @@ package docker import ( - "bytes" "encoding/json" "fmt" "github.com/dotcloud/docker/auth" @@ -631,32 +630,24 @@ func Upload(w http.ResponseWriter, req *http.Request) { } func postBuild(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - - Upload(w, r) - - // io.Copy(os.Stderr, r.Body) - - if err := r.ParseMultipartForm(409699); err != nil { - utils.Debugf("----- %s\n", err) + if err := r.ParseMultipartForm(4096); err != nil { return err } - mpr, err := r.MultipartReader() + file, _, err := r.FormFile("Dockerfile") if err != nil { return err } - p, err := mpr.NextPart() + context, _, err := r.FormFile("Context") if err != nil { - return err + if err != http.ErrMissingFile { + return err + } } - dockerfile := make([]byte, 4096) - p.Read(dockerfile) - - utils.Debugf("Dockerfile >>>%s<<<\n", dockerfile) b := NewBuildFile(srv, w) - if _, err := b.Build(bytes.NewReader(dockerfile)); err != nil { + if _, err := b.Build(file, context); err != nil { return err } return nil diff --git a/builder_client.go b/builder_client.go index e0a55ae6c..0b511ee21 100644 --- a/builder_client.go +++ b/builder_client.go @@ -255,7 +255,7 @@ func (b *builderClient) commit(id string) error { return nil } -func (b *builderClient) Build(dockerfile io.Reader) (string, error) { +func (b *builderClient) Build(dockerfile, context io.Reader) (string, error) { defer b.clearTmp(b.tmpContainers, b.tmpImages) file := bufio.NewReader(dockerfile) for { diff --git a/commands.go b/commands.go index 4291b1d8d..f5c658e6b 100644 --- a/commands.go +++ b/commands.go @@ -57,7 +57,7 @@ func (cli *DockerCli) CmdHelp(args ...string) error { 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", - "build": "Build a container from Dockerfile or via stdin", + "build": "Build a container from a Dockerfile", "commit": "Create a new image from a container's changes", "diff": "Inspect changes on a container's filesystem", "export": "Stream the contents of a container as a tar archive", @@ -112,36 +112,67 @@ func (cli *DockerCli) CmdInsert(args ...string) error { } func (cli *DockerCli) CmdBuild(args ...string) error { + cmd := Subcmd("build", "[OPTIONS]", "Build an image from a Dockerfile") + fileName := cmd.String("f", "Dockerfile", "Use file as Dockerfile. Can be '-' for stdin") + contextPath := cmd.String("c", "", "Use the specified directory as context for the build") + if err := cmd.Parse(args); err != nil { + return nil + } + var ( + file io.ReadCloser + multipartBody io.Reader + err error + ) + + // Init the needed component for the Multipart buff := bytes.NewBuffer([]byte{}) - + multipartBody = buff w := multipart.NewWriter(buff) + boundary := strings.NewReader("\r\n--" + w.Boundary() + "--\r\n") - dockerfile, err := w.CreateFormFile("Dockerfile", "Dockerfile") + // Create a FormFile multipart for the Dockerfile + if *fileName == "-" { + file = os.Stdin + } else { + file, err = os.Open(*fileName) + if err != nil { + return err + } + defer file.Close() + } + if _, err := w.CreateFormFile("Dockerfile", *fileName); err != nil { + return err + } + multipartBody = io.MultiReader(multipartBody, file) + + // Create a FormFile multipart for the context if needed + if *contextPath != "" { + // FIXME: Use NewTempArchive in order to have the size and avoid too much memory usage? + context, err := Tar(*contextPath, Bzip2) + if err != nil { + return err + } + if _, err := w.CreateFormFile("Context", *contextPath+".tar.bz2"); err != nil { + return err + } + multipartBody = io.MultiReader(multipartBody, utils.ProgressReader(ioutil.NopCloser(context), -1, os.Stdout, "Uploading Context %v/%v (%v)")) + } + + // Send the multipart request with correct content-type + req, err := http.NewRequest("POST", fmt.Sprintf("http://%s:%d%s", cli.host, cli.port, "/build"), io.MultiReader(multipartBody, boundary)) if err != nil { return err } - file, err := os.Open("Dockerfile") - if err != nil { - return err - } - dockerfile.Write([]byte(w.Boundary() + "\r\n")) - if _, err := io.Copy(dockerfile, file); err != nil { - return err - } - dockerfile.Write([]byte("\r\n" + w.Boundary())) + req.Header.Set("Content-Type", w.FormDataContentType()) - // req, err := http.NewRequest("POST", fmt.Sprintf("http://%s:%d%s", cli.host, cli.port, "/build"), buff) - // if err != nil { - // return err - // } - // req.Header.Set("Content-Type", w.FormDataContentType()) - resp, err := http.Post(fmt.Sprintf("http://%s:%d%s", cli.host, cli.port, "/build"), w.FormDataContentType(), buff) + resp, err := http.DefaultClient.Do(req) if err != nil { return err } defer resp.Body.Close() + // Check for errors if resp.StatusCode < 200 || resp.StatusCode >= 400 { body, err := ioutil.ReadAll(resp.Body) if err != nil { @@ -150,6 +181,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error { return fmt.Errorf("error: %s", body) } + // Output the result if _, err := io.Copy(os.Stdout, resp.Body); err != nil { return err } @@ -180,7 +212,7 @@ func (cli *DockerCli) CmdBuildClient(args ...string) error { return err } } - if _, err := NewBuilderClient("0.0.0.0", 4243).Build(file); err != nil { + if _, err := NewBuilderClient("0.0.0.0", 4243).Build(file, nil); err != nil { return err } return nil From e3f04298597195a95557c4224c05df752dc08695 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Thu, 23 May 2013 18:33:31 -0700 Subject: [PATCH 51/95] Add missing buildfile.go --- buildfile.go | 311 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 311 insertions(+) create mode 100644 buildfile.go diff --git a/buildfile.go b/buildfile.go new file mode 100644 index 000000000..0784f5432 --- /dev/null +++ b/buildfile.go @@ -0,0 +1,311 @@ +package docker + +import ( + "bufio" + "encoding/json" + "fmt" + "github.com/dotcloud/docker/utils" + "io" + "os" + "reflect" + "strings" +) + +type BuildFile interface { + Build(io.Reader, io.Reader) (string, error) + CmdFrom(string) error + CmdRun(string) error +} + +type buildFile struct { + runtime *Runtime + builder *Builder + srv *Server + + image string + maintainer string + config *Config + + tmpContainers map[string]struct{} + tmpImages map[string]struct{} + + needCommit bool + + out io.Writer +} + +func (b *buildFile) clearTmp(containers, images map[string]struct{}) { + for c := range containers { + tmp := b.runtime.Get(c) + b.runtime.Destroy(tmp) + utils.Debugf("Removing container %s", c) + } + for i := range images { + b.runtime.graph.Delete(i) + utils.Debugf("Removing image %s", i) + } +} + +func (b *buildFile) CmdFrom(name string) error { + image, err := b.runtime.repositories.LookupImage(name) + if err != nil { + if b.runtime.graph.IsNotExist(err) { + + var tag, remote string + if strings.Contains(name, ":") { + remoteParts := strings.Split(name, ":") + tag = remoteParts[1] + remote = remoteParts[0] + } else { + remote = name + } + + if err := b.srv.ImagePull(remote, tag, "", b.out); err != nil { + return err + } + + image, err = b.runtime.repositories.LookupImage(name) + if err != nil { + return err + } + } else { + return err + } + } + b.image = image.Id + b.config = &Config{} + return nil +} + +func (b *buildFile) CmdMaintainer(name string) error { + b.needCommit = true + b.maintainer = name + return nil +} + +func (b *buildFile) CmdRun(args string) error { + if b.image == "" { + return fmt.Errorf("Please provide a source image with `from` prior to run") + } + config, _, err := ParseRun([]string{b.image, "/bin/sh", "-c", args}, nil) + if err != nil { + return err + } + + cmd, env := b.config.Cmd, b.config.Env + b.config.Cmd = nil + MergeConfig(b.config, config) + + if cache, err := b.srv.ImageGetCached(b.image, config); err != nil { + return err + } else if cache != nil { + utils.Debugf("Use cached version") + b.image = cache.Id + return nil + } + + cid, err := b.run() + if err != nil { + return err + } + b.config.Cmd, b.config.Env = cmd, env + return b.commit(cid) +} + +func (b *buildFile) CmdEnv(args string) error { + b.needCommit = true + tmp := strings.SplitN(args, " ", 2) + if len(tmp) != 2 { + return fmt.Errorf("Invalid ENV format") + } + key := strings.Trim(tmp[0], " ") + value := strings.Trim(tmp[1], " ") + + for i, elem := range b.config.Env { + if strings.HasPrefix(elem, key+"=") { + b.config.Env[i] = key + "=" + value + return nil + } + } + b.config.Env = append(b.config.Env, key+"="+value) + return nil +} + +func (b *buildFile) CmdCmd(args string) error { + b.needCommit = true + var cmd []string + if err := json.Unmarshal([]byte(args), &cmd); err != nil { + utils.Debugf("Error unmarshalling: %s, using /bin/sh -c", err) + b.config.Cmd = []string{"/bin/sh", "-c", args} + } else { + b.config.Cmd = cmd + } + return nil +} + +func (b *buildFile) CmdExpose(args string) error { + ports := strings.Split(args, " ") + b.config.PortSpecs = append(ports, b.config.PortSpecs...) + return nil +} + +func (b *buildFile) CmdInsert(args string) error { + if b.image == "" { + return fmt.Errorf("Please provide a source image with `from` prior to insert") + } + tmp := strings.SplitN(args, " ", 2) + if len(tmp) != 2 { + return fmt.Errorf("Invalid INSERT format") + } + sourceUrl := strings.Trim(tmp[0], " ") + destPath := strings.Trim(tmp[1], " ") + + file, err := utils.Download(sourceUrl, b.out) + if err != nil { + return err + } + defer file.Body.Close() + + cid, err := b.run() + if err != nil { + return err + } + + container := b.runtime.Get(cid) + if container == nil { + return fmt.Errorf("An error occured while creating the container") + } + + if err := container.Inject(file.Body, destPath); err != nil { + return err + } + + return b.commit(cid) +} + +func (b *buildFile) run() (string, error) { + if b.image == "" { + return "", fmt.Errorf("Please provide a source image with `from` prior to run") + } + b.config.Image = b.image + + // Create the container and start it + c, err := b.builder.Create(b.config) + if err != nil { + return "", err + } + b.tmpContainers[c.Id] = struct{}{} + + //start the container + if err := c.Start(); err != nil { + return "", err + } + + // Wait for it to finish + if ret := c.Wait(); ret != 0 { + return "", fmt.Errorf("The command %v returned a non-zero code: %d", b.config.Cmd, ret) + } + + return c.Id, nil +} + +func (b *buildFile) commit(id string) error { + if b.image == "" { + return fmt.Errorf("Please provide a source image with `from` prior to commit") + } + b.config.Image = b.image + + if id == "" { + cmd := b.config.Cmd + b.config.Cmd = []string{"true"} + if cid, err := b.run(); err != nil { + return err + } else { + id = cid + } + b.config.Cmd = cmd + } + + container := b.runtime.Get(id) + if container == nil { + return fmt.Errorf("An error occured while creating the container") + } + + // Commit the container + image, err := b.builder.Commit(container, "", "", "", b.maintainer, nil) + if err != nil { + return err + } + b.tmpImages[image.Id] = struct{}{} + b.image = image.Id + b.needCommit = false + return nil +} + +func (b *buildFile) Build(dockerfile, context io.Reader) (string, error) { + b.out = os.Stdout + + defer b.clearTmp(b.tmpContainers, b.tmpImages) + file := bufio.NewReader(dockerfile) + for { + line, err := file.ReadString('\n') + if err != nil { + if err == io.EOF { + break + } + return "", err + } + line = strings.Replace(strings.TrimSpace(line), " ", " ", 1) + // Skip comments and empty line + if len(line) == 0 || line[0] == '#' { + continue + } + tmp := strings.SplitN(line, " ", 2) + if len(tmp) != 2 { + return "", fmt.Errorf("Invalid Dockerfile format") + } + instruction := strings.ToLower(strings.Trim(tmp[0], " ")) + arguments := strings.Trim(tmp[1], " ") + + fmt.Fprintf(b.out, "%s %s (%s)\n", strings.ToUpper(instruction), arguments, b.image) + + method, exists := reflect.TypeOf(b).MethodByName("Cmd" + strings.ToUpper(instruction[:1]) + strings.ToLower(instruction[1:])) + if !exists { + fmt.Fprintf(b.out, "Skipping unknown instruction %s\n", strings.ToUpper(instruction)) + } + ret := method.Func.Call([]reflect.Value{reflect.ValueOf(b), reflect.ValueOf(arguments)})[0].Interface() + if ret != nil { + return "", ret.(error) + } + + fmt.Fprintf(b.out, "===> %v\n", b.image) + } + if b.needCommit { + if err := b.commit(""); err != nil { + return "", err + } + } + if b.image != "" { + // The build is successful, keep the temporary containers and images + for i := range b.tmpImages { + delete(b.tmpImages, i) + } + fmt.Fprintf(b.out, "Build finished. image id: %s\n", b.image) + return b.image, nil + } + for i := range b.tmpContainers { + delete(b.tmpContainers, i) + } + return "", fmt.Errorf("An error occured during the build\n") +} + +func NewBuildFile(srv *Server, out io.Writer) BuildFile { + return &buildFile{ + builder: NewBuilder(srv.runtime), + runtime: srv.runtime, + srv: srv, + config: &Config{}, + tmpContainers: make(map[string]struct{}), + tmpImages: make(map[string]struct{}), + } +} From 2cd00a47a5a8f405eb6a7b3f34edaf38c89e9b1c Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Thu, 23 May 2013 18:34:38 -0700 Subject: [PATCH 52/95] remove unused function --- api.go | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/api.go b/api.go index 0a65543b7..d3eb9101b 100644 --- a/api.go +++ b/api.go @@ -599,36 +599,6 @@ func postImagesGetCache(srv *Server, w http.ResponseWriter, r *http.Request, var return nil } -func Upload(w http.ResponseWriter, req *http.Request) { - - mr, err := req.MultipartReader() - if err != nil { - return - } - length := req.ContentLength - for { - - part, err := mr.NextPart() - if err == io.EOF { - break - } - var read int64 - var p float32 - for { - buffer := make([]byte, 100000) - cBytes, err := part.Read(buffer) - if err == io.EOF { - break - } - read = read + int64(cBytes) - //fmt.Printf("read: %v \n",read ) - p = float32(read) / float32(length) * 100 - fmt.Printf("progress: %v \n", p) - os.Stdout.Write(buffer) - } - } -} - func postBuild(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := r.ParseMultipartForm(4096); err != nil { return err From 70d2123efda0e92760b96b03ce27cb4f1fb61cb3 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Thu, 23 May 2013 19:33:28 -0700 Subject: [PATCH 53/95] Add resize endpoint to api --- api.go | 24 ++++++++++++++++++++++++ container.go | 4 ++++ server.go | 7 +++++++ 3 files changed, 35 insertions(+) diff --git a/api.go b/api.go index 0a902c404..6e2b425f0 100644 --- a/api.go +++ b/api.go @@ -48,6 +48,7 @@ func writeJson(w http.ResponseWriter, b []byte) { w.Write(b) } +// FIXME: Use stvconv.ParseBool() instead? func getBoolParam(value string) (bool, error) { if value == "1" || strings.ToLower(value) == "true" { return true, nil @@ -485,6 +486,28 @@ func postContainersWait(srv *Server, version float64, w http.ResponseWriter, r * return nil } +func postContainersResize(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { + if err := parseForm(r); err != nil { + return err + } + height, err := strconv.Atoi(r.Form.Get("h")) + if err != nil { + return err + } + width, err := strconv.Atoi(r.Form.Get("w")) + if err != nil { + return err + } + if vars == nil { + return fmt.Errorf("Missing parameter") + } + name := vars["name"] + if err := srv.ContainerResize(name, height, width); err != nil { + return err + } + return nil +} + func postContainersAttach(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := parseForm(r); err != nil { return err @@ -620,6 +643,7 @@ func ListenAndServe(addr string, srv *Server, logging bool) error { "/containers/{name:.*}/start": postContainersStart, "/containers/{name:.*}/stop": postContainersStop, "/containers/{name:.*}/wait": postContainersWait, + "/containers/{name:.*}/resize": postContainersResize, "/containers/{name:.*}/attach": postContainersAttach, }, "DELETE": { diff --git a/container.go b/container.go index a82ce0291..8cba8f598 100644 --- a/container.go +++ b/container.go @@ -754,6 +754,10 @@ func (container *Container) Wait() int { return container.State.ExitCode } +func (container *Container) Resize(h, w int) error { + return fmt.Errorf("Resize not yet implemented") +} + func (container *Container) ExportRw() (Archive, error) { return Tar(container.rwPath(), Uncompressed) } diff --git a/server.go b/server.go index 564b1c812..144f180e4 100644 --- a/server.go +++ b/server.go @@ -776,6 +776,13 @@ func (srv *Server) ContainerWait(name string) (int, error) { return 0, fmt.Errorf("No such container: %s", name) } +func (srv *Server) ContainerResize(name string, h, w int) error { + if container := srv.runtime.Get(name); container != nil { + return container.Resize(h, w) + } + return fmt.Errorf("No such container: %s", name) +} + func (srv *Server) ContainerAttach(name string, logs, stream, stdin, stdout, stderr bool, in io.ReadCloser, out io.Writer) error { container := srv.runtime.Get(name) if container == nil { From a7d7a0665573b3db46963e4eb083f24470aad082 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Fri, 24 May 2013 12:23:28 +0000 Subject: [PATCH 54/95] change %f to %g --- commands.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands.go b/commands.go index 6212459b4..8112af021 100644 --- a/commands.go +++ b/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 4dab2fccd39858c0fb3b783a612fb95173d34f7b Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Fri, 24 May 2013 12:43:24 +0000 Subject: [PATCH 55/95] removed useless params --- commands.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/commands.go b/commands.go index db073f7d4..a85a12745 100644 --- a/commands.go +++ b/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 1f23b4caae6cd60a2bc1911c17fcebcadc539497 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Fri, 24 May 2013 14:23:43 +0000 Subject: [PATCH 56/95] fix docker login when same username --- api.go | 8 ++++---- commands.go | 4 ++-- registry/registry.go | 7 ++++++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/api.go b/api.go index 0a902c404..216ae027e 100644 --- a/api.go +++ b/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/commands.go b/commands.go index 75ba562cd..8c4630b82 100644 --- a/commands.go +++ b/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/registry/registry.go b/registry/registry.go index ce9b4b4ac..bd361b5e7 100644 --- a/registry/registry.go +++ b/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 8dc2ad2c06fabb6501f0adff80761898bed5bc6f Mon Sep 17 00:00:00 2001 From: kim0 Date: Fri, 24 May 2013 17:44:02 +0200 Subject: [PATCH 57/95] Avoid hardcoding kernel 3.8 version, allow Ubuntu updates to work --- docs/sources/installation/ubuntulinux.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sources/installation/ubuntulinux.rst b/docs/sources/installation/ubuntulinux.rst index 6d2d3e671..0aaa76250 100644 --- a/docs/sources/installation/ubuntulinux.rst +++ b/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 4e576f047fc8a5a75fa88a66132bdade4f3a1e44 Mon Sep 17 00:00:00 2001 From: kim0 Date: Fri, 24 May 2013 18:55:32 +0300 Subject: [PATCH 58/95] Properly install ppa, avoid GPG key warning --- docs/sources/installation/ubuntulinux.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/sources/installation/ubuntulinux.rst b/docs/sources/installation/ubuntulinux.rst index 6d2d3e671..82d44827a 100644 --- a/docs/sources/installation/ubuntulinux.rst +++ b/docs/sources/installation/ubuntulinux.rst @@ -54,9 +54,9 @@ which makes installing Docker on Ubuntu very easy. .. code-block:: bash # Add the PPA sources to your apt sources list. - sudo sh -c "echo 'deb http://ppa.launchpad.net/dotcloud/lxc-docker/ubuntu precise main' > /etc/apt/sources.list.d/lxc-docker.list" + sudo apt-get install python-software-properties && sudo add-apt-repository ppa:dotcloud/lxc-docker - # Update your sources, you will see a warning. + # Update your sources sudo apt-get update # Install, you will see another warning that the package cannot be authenticated. Confirm install. From 92e4a51965ce862ad1b4682a68b33550f2fd613f Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Fri, 24 May 2013 16:49:18 +0000 Subject: [PATCH 59/95] use -H --- commands.go | 2 +- docker/docker.go | 2 +- docs/sources/commandline/cli.rst | 2 +- docs/sources/use/basics.rst | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/commands.go b/commands.go index 8112af021..5333ec40c 100644 --- a/commands.go +++ b/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/docker/docker.go b/docker/docker.go index f2dca2de1..28b4d7f92 100644 --- a/docker/docker.go +++ b/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/docs/sources/commandline/cli.rst b/docs/sources/commandline/cli.rst index 3bb904b46..02691b4f5 100644 --- a/docs/sources/commandline/cli.rst +++ b/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/docs/sources/use/basics.rst b/docs/sources/use/basics.rst index 4c450fbc9..378028703 100644 --- a/docs/sources/use/basics.rst +++ b/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 deb9963e6e5871d53ab1d75c90bbf2da53ffcb36 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Fri, 24 May 2013 11:07:32 -0700 Subject: [PATCH 60/95] Catch sigwinch client --- commands.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/commands.go b/commands.go index 75ba562cd..2b96f64f0 100644 --- a/commands.go +++ b/commands.go @@ -15,10 +15,12 @@ import ( "net/http/httputil" "net/url" "os" + "os/signal" "path/filepath" "reflect" "strconv" "strings" + "syscall" "text/tabwriter" "time" "unicode" @@ -33,6 +35,19 @@ var ( func ParseCommands(args ...string) error { cli := NewDockerCli("0.0.0.0", 4243) + c := make(chan os.Signal, 1) + signal.Notify(c, syscall.SIGWINCH) + go func() { + for sig := range c { + if sig == syscall.SIGWINCH { + _, _, err := cli.call("GET", "/auth", nil) + if err != nil { + utils.Debugf("Error resize: %s", err) + } + } + } + }() + if len(args) > 0 { methodName := "Cmd" + strings.ToUpper(args[0][:1]) + strings.ToLower(args[0][1:]) method, exists := reflect.TypeOf(cli).MethodByName(methodName) @@ -1294,6 +1309,6 @@ func NewDockerCli(host string, port int) *DockerCli { } type DockerCli struct { - host string - port int + host string + port int } From 0146f65a448d2d42271300f1477ea9fa378d6360 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Fri, 24 May 2013 11:31:11 -0700 Subject: [PATCH 61/95] Fix issue within auth test --- api_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api_test.go b/api_test.go index de4289728..06413e130 100644 --- a/api_test.go +++ b/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 ae72c2f4d6c37a14fcd81658f6ae42d65f5c7169 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Fri, 24 May 2013 11:31:19 -0700 Subject: [PATCH 62/95] Gofmt --- docker/docker.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/docker.go b/docker/docker.go index 28b4d7f92..1749b2fd3 100644 --- a/docker/docker.go +++ b/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 bfb65b733a2cfa0dac6a5760897f09d8e2557381 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Fri, 24 May 2013 11:31:36 -0700 Subject: [PATCH 63/95] Simplify the Host flag parsing --- docker/docker.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docker/docker.go b/docker/docker.go index 1749b2fd3..7b8aa7f85 100644 --- a/docker/docker.go +++ b/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 a3293ed854675074d7f5d5c2bca63ba9fa599deb Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Fri, 24 May 2013 11:56:21 -0700 Subject: [PATCH 64/95] Fix merge issue --- api.go | 1 - commands.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/api.go b/api.go index 216ae027e..a99828e96 100644 --- a/api.go +++ b/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/commands.go b/commands.go index 1c83e3045..862222513 100644 --- a/commands.go +++ b/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]) From c5f15dcd3de02a10452963a9c56cb2e587972f58 Mon Sep 17 00:00:00 2001 From: Thatcher Peskens Date: Fri, 24 May 2013 14:42:00 -0700 Subject: [PATCH 65/95] Added links to @jpetazzo 's kernel article, removed quote indents from puppet.rst --- docs/sources/installation/binaries.rst | 2 +- docs/sources/installation/ubuntulinux.rst | 2 +- docs/sources/use/puppet.rst | 64 +++++++++++------------ 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/docs/sources/installation/binaries.rst b/docs/sources/installation/binaries.rst index 8bab5695c..e7a07b6db 100644 --- a/docs/sources/installation/binaries.rst +++ b/docs/sources/installation/binaries.rst @@ -27,7 +27,7 @@ But we know people have had success running it under Dependencies: ------------- -* 3.8 Kernel +* 3.8 Kernel (read more about :ref:`kernel`) * AUFS filesystem support * lxc * bsdtar diff --git a/docs/sources/installation/ubuntulinux.rst b/docs/sources/installation/ubuntulinux.rst index 0aaa76250..ac94913eb 100644 --- a/docs/sources/installation/ubuntulinux.rst +++ b/docs/sources/installation/ubuntulinux.rst @@ -16,7 +16,7 @@ Right now, the officially supported distribution are: Docker has the following dependencies -* Linux kernel 3.8 +* Linux kernel 3.8 (read more about :ref:`kernel`) * AUFS file system support (we are working on BTRFS support as an alternative) .. _ubuntu_precise: diff --git a/docs/sources/use/puppet.rst b/docs/sources/use/puppet.rst index 1c48aec8e..5606f2a86 100644 --- a/docs/sources/use/puppet.rst +++ b/docs/sources/use/puppet.rst @@ -25,9 +25,9 @@ Installation The module is available on the `Puppet Forge `_ and can be installed using the built-in module tool. - .. code-block:: bash +.. code-block:: bash - puppet module install garethr/docker + puppet module install garethr/docker It can also be found on `GitHub `_ if you would rather download the source. @@ -41,9 +41,9 @@ for managing images and containers. Installation ~~~~~~~~~~~~ - .. code-block:: ruby +.. code-block:: ruby - include 'docker' + include 'docker' Images ~~~~~~ @@ -51,26 +51,26 @@ Images The next step is probably to install a docker image, for this we have a defined type which can be used like so: - .. code-block:: ruby +.. code-block:: ruby - docker::image { 'base': } + docker::image { 'base': } This is equivalent to running: - .. code-block:: bash +.. code-block:: bash - docker pull base + docker pull base Note that it will only if the image of that name does not already exist. This is downloading a large binary so on first run can take a while. For that reason this define turns off the default 5 minute timeout for exec. Note that you can also remove images you no longer need with: - .. code-block:: ruby +.. code-block:: ruby - docker::image { 'base': - ensure => 'absent', - } + docker::image { 'base': + ensure => 'absent', + } Containers ~~~~~~~~~~ @@ -78,35 +78,35 @@ Containers Now you have an image you can run commands within a container managed by docker. - .. code-block:: ruby +.. code-block:: ruby - docker::run { 'helloworld': - image => 'base', - command => '/bin/sh -c "while true; do echo hello world; sleep 1; done"', - } + docker::run { 'helloworld': + image => 'base', + command => '/bin/sh -c "while true; do echo hello world; sleep 1; done"', + } This is equivalent to running the following command, but under upstart: - .. code-block:: bash +.. code-block:: bash - docker run -d base /bin/sh -c "while true; do echo hello world; sleep 1; done" + docker run -d base /bin/sh -c "while true; do echo hello world; sleep 1; done" Run also contains a number of optional parameters: - .. code-block:: ruby +.. code-block:: ruby - docker::run { 'helloworld': - image => 'base', - command => '/bin/sh -c "while true; do echo hello world; sleep 1; done"', - ports => ['4444', '4555'], - volumes => ['/var/lib/counchdb', '/var/log'], - volumes_from => '6446ea52fbc9', - memory_limit => 10485760, # bytes - username => 'example', - hostname => 'example.com', - env => ['FOO=BAR', 'FOO2=BAR2'], - dns => ['8.8.8.8', '8.8.4.4'], - } + docker::run { 'helloworld': + image => 'base', + command => '/bin/sh -c "while true; do echo hello world; sleep 1; done"', + ports => ['4444', '4555'], + volumes => ['/var/lib/counchdb', '/var/log'], + volumes_from => '6446ea52fbc9', + memory_limit => 10485760, # bytes + username => 'example', + hostname => 'example.com', + env => ['FOO=BAR', 'FOO2=BAR2'], + dns => ['8.8.8.8', '8.8.4.4'], + } Note that ports, env, dns and volumes can be set with either a single string or as above with an array of values. From 88ef309a940bcbb6f85a750372b8fdbc6569c3a7 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Fri, 24 May 2013 14:44:16 -0700 Subject: [PATCH 66/95] Finish resize implementation client and server --- commands.go | 42 +++++++++++++++++++++++++++++------------- container.go | 7 ++++++- term/term.go | 23 +++++++++++++++++++++-- 3 files changed, 56 insertions(+), 16 deletions(-) diff --git a/commands.go b/commands.go index 2b96f64f0..099c3686c 100644 --- a/commands.go +++ b/commands.go @@ -35,19 +35,6 @@ var ( func ParseCommands(args ...string) error { cli := NewDockerCli("0.0.0.0", 4243) - c := make(chan os.Signal, 1) - signal.Notify(c, syscall.SIGWINCH) - go func() { - for sig := range c { - if sig == syscall.SIGWINCH { - _, _, err := cli.call("GET", "/auth", nil) - if err != nil { - utils.Debugf("Error resize: %s", err) - } - } - } - }() - if len(args) > 0 { methodName := "Cmd" + strings.ToUpper(args[0][:1]) + strings.ToLower(args[0][1:]) method, exists := reflect.TypeOf(cli).MethodByName(methodName) @@ -975,6 +962,7 @@ func (cli *DockerCli) CmdAttach(args ...string) error { v.Set("stderr", "1") v.Set("stdin", "1") + cli.monitorTtySize(cmd.Arg(0)) if err := cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), container.Config.Tty); err != nil { return err } @@ -1162,6 +1150,7 @@ func (cli *DockerCli) CmdRun(args ...string) error { } if config.AttachStdin || config.AttachStdout || config.AttachStderr { + cli.monitorTtySize(out.Id) if err := cli.hijack("POST", "/containers/"+out.Id+"/attach?"+v.Encode(), config.Tty); err != nil { return err } @@ -1295,6 +1284,33 @@ func (cli *DockerCli) hijack(method, path string, setRawTerminal bool) error { } +func (cli *DockerCli) resizeTty(id string) { + ws, err := term.GetWinsize(os.Stdin.Fd()) + if err != nil { + utils.Debugf("Error getting size: %s", err) + } + v := url.Values{} + v.Set("h", strconv.Itoa(int(ws.Height))) + v.Set("w", strconv.Itoa(int(ws.Width))) + if _, _, err := cli.call("POST", "/containers/"+id+"/resize?"+v.Encode(), nil); err != nil { + utils.Debugf("Error resize: %s", err) + } +} + +func (cli *DockerCli) monitorTtySize(id string) { + cli.resizeTty(id) + + c := make(chan os.Signal, 1) + signal.Notify(c, syscall.SIGWINCH) + go func() { + for sig := range c { + if sig == syscall.SIGWINCH { + cli.resizeTty(id) + } + } + }() +} + func Subcmd(name, signature, description string) *flag.FlagSet { flags := flag.NewFlagSet(name, flag.ContinueOnError) flags.Usage = func() { diff --git a/container.go b/container.go index 8cba8f598..c6b7c8a51 100644 --- a/container.go +++ b/container.go @@ -4,6 +4,7 @@ import ( "encoding/json" "flag" "fmt" + "github.com/dotcloud/docker/term" "github.com/dotcloud/docker/utils" "github.com/kr/pty" "io" @@ -755,7 +756,11 @@ func (container *Container) Wait() int { } func (container *Container) Resize(h, w int) error { - return fmt.Errorf("Resize not yet implemented") + pty, ok := container.ptyMaster.(*os.File) + if !ok { + return fmt.Errorf("ptyMaster does not have Fd() method") + } + return term.SetWinsize(pty.Fd(), &term.Winsize{Height: uint16(h), Width: uint16(w)}) } func (container *Container) ExportRw() (Archive, error) { diff --git a/term/term.go b/term/term.go index 8c07b9335..d0f303f4e 100644 --- a/term/term.go +++ b/term/term.go @@ -1,6 +1,7 @@ package term import ( + "github.com/dotcloud/docker/utils" "os" "os/signal" "syscall" @@ -109,17 +110,35 @@ type State struct { termios Termios } +type Winsize struct { + Width uint16 + Height uint16 + x uint16 + y uint16 +} + +func GetWinsize(fd uintptr) (*Winsize, error) { + ws := &Winsize{} + _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(ws))) + return ws, err +} + +func SetWinsize(fd uintptr, ws *Winsize) error { + _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(syscall.TIOCSWINSZ), uintptr(unsafe.Pointer(ws))) + return err +} + // IsTerminal returns true if the given file descriptor is a terminal. func IsTerminal(fd int) bool { var termios Termios - _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(getTermios), uintptr(unsafe.Pointer(&termios)), 0, 0, 0) + _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), uintptr(getTermios), uintptr(unsafe.Pointer(&termios))) return err == 0 } // Restore restores the terminal connected to the given file descriptor to a // previous state. func Restore(fd int, state *State) error { - _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(setTermios), uintptr(unsafe.Pointer(&state.termios)), 0, 0, 0) + _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), uintptr(setTermios), uintptr(unsafe.Pointer(&state.termios))) return err } From b438565609917439cb4172717e5505c265c4e291 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Fri, 24 May 2013 14:48:13 -0700 Subject: [PATCH 67/95] Fix merge issue --- commands.go | 8 ++++---- term/term.go | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/commands.go b/commands.go index 1b94fea45..f42927732 100644 --- a/commands.go +++ b/commands.go @@ -71,7 +71,7 @@ func (cli *DockerCli) CmdHelp(args ...string) error { return nil } } - 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.host, cli.port) for cmd, description := range map[string]string{ "attach": "Attach to a running container", "build": "Build a container from Dockerfile or via stdin", @@ -1201,7 +1201,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/v%g%s", cli.addr, cli.port, API_VERSION, path), params) + req, err := http.NewRequest(method, fmt.Sprintf("http://%s:%d/v%g%s", cli.host, cli.port, API_VERSION, path), params) if err != nil { return nil, -1, err } @@ -1233,7 +1233,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%g%s", cli.addr, cli.port, API_VERSION, path), in) + req, err := http.NewRequest(method, fmt.Sprintf("http://%s:%d/v%g%s", cli.host, cli.port, API_VERSION, path), in) if err != nil { return err } @@ -1269,7 +1269,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.addr, cli.port)) + dial, err := net.Dial("tcp", fmt.Sprintf("%s:%d", cli.host, cli.port)) if err != nil { return err } diff --git a/term/term.go b/term/term.go index d0f303f4e..290bf174a 100644 --- a/term/term.go +++ b/term/term.go @@ -1,7 +1,6 @@ package term import ( - "github.com/dotcloud/docker/utils" "os" "os/signal" "syscall" From 194f48774992644257bf7cf0878e47e9834d40e1 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Fri, 24 May 2013 18:31:47 -0700 Subject: [PATCH 68/95] Added FIXME about possible race condition in a unit test --- server_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server_test.go b/server_test.go index 7b9025286..b96e1dd5e 100644 --- a/server_test.go +++ b/server_test.go @@ -85,6 +85,7 @@ func TestCreateStartRestartStopStartKillRm(t *testing.T) { t.Fatal(err) } + // FIXME: this failed once with a race condition ("Unable to remove filesystem for xxx: directory not empty") if err = srv.ContainerDestroy(id, true); err != nil { t.Fatal(err) } From bb4b35a8920bcba8b60784297650ced5b2e01e47 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Fri, 24 May 2013 18:32:21 -0700 Subject: [PATCH 69/95] Fix a unit test broken by pull request #703 --- runtime_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/runtime_test.go b/runtime_test.go index 01bd2a012..6c4ec5ded 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -75,11 +75,13 @@ func init() { registry: registry.NewRegistry(runtime.root), } // Retrieve the Image - if err := srv.ImagePull(unitTestImageName, "", "", os.Stdout); err != nil { + if err := srv.ImagePull(unitTestImageName, "", "", os.Stdout, false); err != nil { panic(err) } } +// FIXME: test that ImagePull(json=true) send correct json output + func newTestRuntime() (*Runtime, error) { root, err := ioutil.TempDir("", "docker-test") if err != nil { From df23a1e675c7e3cbad617374d85c48103541ee14 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Fri, 24 May 2013 18:58:24 -0700 Subject: [PATCH 70/95] * Registry: specified naming restrictions for usernames and repository names --- docs/sources/api/registry_api.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/sources/api/registry_api.rst b/docs/sources/api/registry_api.rst index f33ca187b..7034d90e2 100644 --- a/docs/sources/api/registry_api.rst +++ b/docs/sources/api/registry_api.rst @@ -301,7 +301,7 @@ POST /v1/users {"email": "sam@dotcloud.com", "password": "toto42", "username": "foobar"'} **Validation**: - - **username** : min 4 character, max 30 characters, all lowercase no special characters. + - **username** : min 4 character, max 30 characters, must match the regular expression [a-z0-9_]. - **password**: min 5 characters **Valid**: return HTTP 200 @@ -345,6 +345,11 @@ GET /v1/users The Registry does not know anything about users. Even though repositories are under usernames, it’s just a namespace for the registry. Allowing us to implement organizations or different namespaces per user later, without modifying the Registry’s API. +The following naming restrictions apply: + +- Namespaces must match the same regular expression as usernames (See 4.2.1.) +- Repository names must match the regular expression [a-zA-Z0-9-_.] + 4.3.1 Get all tags ^^^^^^^^^^^^^^^^^^ From 7d6ff7be129d70f0ff5c50a47d70a32a1e6274bc Mon Sep 17 00:00:00 2001 From: Mark McGranaghan Date: Tue, 28 May 2013 06:27:12 -0700 Subject: [PATCH 71/95] Fix attach API docs. --- docs/sources/api/docker_remote_api.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sources/api/docker_remote_api.rst b/docs/sources/api/docker_remote_api.rst index 4c8ebe847..0dcf84273 100644 --- a/docs/sources/api/docker_remote_api.rst +++ b/docs/sources/api/docker_remote_api.rst @@ -378,7 +378,7 @@ Attach to a container .. http:post:: /containers/(id)/attach - Stop the container ``id`` + Attach to the container ``id`` **Example request**: From d9670f427522fc847313ad1b94b1e288dafe7690 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Tue, 28 May 2013 15:06:26 +0000 Subject: [PATCH 72/95] invert status created --- commands.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands.go b/commands.go index 6c4dcd14d..f68bfbad5 100644 --- a/commands.go +++ b/commands.go @@ -806,9 +806,9 @@ func (cli *DockerCli) CmdPs(args ...string) error { for _, out := range outs { if !*quiet { if *noTrunc { - fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s ago\t%s\n", out.Id, out.Image, out.Command, out.Status, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Ports) + fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s ago\t%s\n", out.Id, out.Image, out.Command, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Status, out.Ports) } else { - fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s ago\t%s\n", utils.TruncateId(out.Id), out.Image, utils.Trunc(out.Command, 20), out.Status, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Ports) + fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s ago\t%s\n", utils.TruncateId(out.Id), out.Image, utils.Trunc(out.Command, 20), utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Status, out.Ports) } } else { if *noTrunc { From 4f9443927e8bc8a724b43afae6cf7a183cd9acd0 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Tue, 28 May 2013 16:08:05 +0000 Subject: [PATCH 73/95] rename containers/ps to containers/json --- api.go | 5 +++-- api_test.go | 6 +++--- commands.go | 2 +- docs/sources/api/docker_remote_api.rst | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/api.go b/api.go index 3164a886f..d23b8901b 100644 --- a/api.go +++ b/api.go @@ -206,7 +206,7 @@ func getContainersChanges(srv *Server, version float64, w http.ResponseWriter, r return nil } -func getContainersPs(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func getContainersJson(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := parseForm(r); err != nil { return err } @@ -627,7 +627,8 @@ func ListenAndServe(addr string, srv *Server, logging bool) error { "/images/search": getImagesSearch, "/images/{name:.*}/history": getImagesHistory, "/images/{name:.*}/json": getImagesByName, - "/containers/ps": getContainersPs, + "/containers/ps": getContainersJson, + "/containers/json": getContainersJson, "/containers/{name:.*}/export": getContainersExport, "/containers/{name:.*}/changes": getContainersChanges, "/containers/{name:.*}/json": getContainersByName, diff --git a/api_test.go b/api_test.go index 06413e130..f94ba23fa 100644 --- a/api_test.go +++ b/api_test.go @@ -318,7 +318,7 @@ func TestGetImagesByName(t *testing.T) { } } -func TestGetContainersPs(t *testing.T) { +func TestGetContainersJson(t *testing.T) { runtime, err := newTestRuntime() if err != nil { t.Fatal(err) @@ -336,13 +336,13 @@ func TestGetContainersPs(t *testing.T) { } defer runtime.Destroy(container) - req, err := http.NewRequest("GET", "/containers?quiet=1&all=1", nil) + req, err := http.NewRequest("GET", "/containers/json?all=1", nil) if err != nil { t.Fatal(err) } r := httptest.NewRecorder() - if err := getContainersPs(srv, API_VERSION, r, req, nil); err != nil { + if err := getContainersJson(srv, API_VERSION, r, req, nil); err != nil { t.Fatal(err) } containers := []ApiContainers{} diff --git a/commands.go b/commands.go index 6c4dcd14d..05d66bce2 100644 --- a/commands.go +++ b/commands.go @@ -788,7 +788,7 @@ func (cli *DockerCli) CmdPs(args ...string) error { v.Set("before", *before) } - body, _, err := cli.call("GET", "/containers/ps?"+v.Encode(), nil) + body, _, err := cli.call("GET", "/containers/json?"+v.Encode(), nil) if err != nil { return err } diff --git a/docs/sources/api/docker_remote_api.rst b/docs/sources/api/docker_remote_api.rst index 0dcf84273..bd87dc7a0 100644 --- a/docs/sources/api/docker_remote_api.rst +++ b/docs/sources/api/docker_remote_api.rst @@ -24,7 +24,7 @@ Docker Remote API List containers *************** -.. http:get:: /containers/ps +.. http:get:: /containers/json List containers @@ -32,7 +32,7 @@ List containers .. sourcecode:: http - GET /containers/ps?all=1&before=8dfafdbc3a40 HTTP/1.1 + GET /containers/json?all=1&before=8dfafdbc3a40 HTTP/1.1 **Example response**: From e5fa4a4956393afc473539710e2a4b7297eb6ebf Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Tue, 28 May 2013 16:19:12 +0000 Subject: [PATCH 74/95] return 404 on no such containers in /attach --- api.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/api.go b/api.go index 3164a886f..581cc84d1 100644 --- a/api.go +++ b/api.go @@ -541,6 +541,10 @@ func postContainersAttach(srv *Server, version float64, w http.ResponseWriter, r } name := vars["name"] + if _, err := srv.ContainerInspect(name); err != nil { + return err + } + in, out, err := hijackServer(w) if err != nil { return err From 525080100d2e2a7899c9a51a1ca57e28e32e8488 Mon Sep 17 00:00:00 2001 From: meejah Date: Tue, 28 May 2013 10:54:32 -0600 Subject: [PATCH 75/95] Use Ubuntu's built-in method to add a PPA repository, which correctly handles keys for you. --- docs/website/gettingstarted/index.html | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/website/gettingstarted/index.html b/docs/website/gettingstarted/index.html index 622cdbbd4..1da2f2cc3 100644 --- a/docs/website/gettingstarted/index.html +++ b/docs/website/gettingstarted/index.html @@ -89,9 +89,10 @@
  • Install Docker

    Add the Ubuntu PPA (Personal Package Archive) sources to your apt sources list, update and install.

    -

    You may see some warnings that the GPG keys cannot be verified.

    +

    This may import a new GPG key (key 63561DC6: public key "Launchpad PPA for dotcloud team" imported).

    -
    sudo sh -c "echo 'deb http://ppa.launchpad.net/dotcloud/lxc-docker/ubuntu precise main' >> /etc/apt/sources.list"
    +
    apt-get install software-properties-common
    +
    add-apt-repository ppa:dotcloud/lxc-docker
    sudo apt-get update
    sudo apt-get install lxc-docker
    From 444f7020cbc639fd781744be207c843aaf663077 Mon Sep 17 00:00:00 2001 From: meejah Date: Tue, 28 May 2013 10:56:26 -0600 Subject: [PATCH 76/95] Add sudo to commands. --- docs/website/gettingstarted/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/website/gettingstarted/index.html b/docs/website/gettingstarted/index.html index 1da2f2cc3..5a8de3232 100644 --- a/docs/website/gettingstarted/index.html +++ b/docs/website/gettingstarted/index.html @@ -91,8 +91,8 @@

    Add the Ubuntu PPA (Personal Package Archive) sources to your apt sources list, update and install.

    This may import a new GPG key (key 63561DC6: public key "Launchpad PPA for dotcloud team" imported).

    -
    apt-get install software-properties-common
    -
    add-apt-repository ppa:dotcloud/lxc-docker
    +
    sudo apt-get install software-properties-common
    +
    sudo add-apt-repository ppa:dotcloud/lxc-docker
    sudo apt-get update
    sudo apt-get install lxc-docker
    From 54db18625aa7154c9dd230907444676fa3079b99 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 28 May 2013 13:37:49 -0700 Subject: [PATCH 77/95] Add Extension() method to Compresison type --- api.go | 1 - archive.go | 17 ++++++++++++++++- buildfile.go | 2 ++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/api.go b/api.go index d3eb9101b..a1a694962 100644 --- a/api.go +++ b/api.go @@ -9,7 +9,6 @@ import ( "io" "log" "net/http" - "os" "strconv" "strings" ) diff --git a/archive.go b/archive.go index 8a011eb6e..4120a52c1 100644 --- a/archive.go +++ b/archive.go @@ -2,6 +2,7 @@ package docker import ( "errors" + "fmt" "io" "io/ioutil" "os" @@ -31,6 +32,20 @@ func (compression *Compression) Flag() string { return "" } +func (compression *Compression) Extension() string { + switch *compression { + case Uncompressed: + return "tar" + case Bzip2: + return "tar.bz2" + case Gzip: + return "tar.gz" + case Xz: + return "tar.xz" + } + return "" +} + func Tar(path string, compression Compression) (io.Reader, error) { cmd := exec.Command("bsdtar", "-f", "-", "-C", path, "-c"+compression.Flag(), ".") return CmdStream(cmd) @@ -41,7 +56,7 @@ func Untar(archive io.Reader, path string) error { cmd.Stdin = archive output, err := cmd.CombinedOutput() if err != nil { - return errors.New(err.Error() + ": " + string(output)) + return fmt.Errorf("%s: %s", err, output) } return nil } diff --git a/buildfile.go b/buildfile.go index 0784f5432..d0f0b6e7d 100644 --- a/buildfile.go +++ b/buildfile.go @@ -6,7 +6,9 @@ import ( "fmt" "github.com/dotcloud/docker/utils" "io" + "io/ioutil" "os" + "path" "reflect" "strings" ) From 6ae3800151025ff73a97c40af578ee714164003b Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 28 May 2013 13:38:26 -0700 Subject: [PATCH 78/95] Implement the CmdAdd instruction --- buildfile.go | 48 +++++++++++++++++++++++++++++++++++++++++++++--- commands.go | 29 ----------------------------- runtime_test.go | 11 ++--------- utils/utils.go | 7 +++++++ 4 files changed, 54 insertions(+), 41 deletions(-) diff --git a/buildfile.go b/buildfile.go index d0f0b6e7d..0cd8aa182 100644 --- a/buildfile.go +++ b/buildfile.go @@ -27,6 +27,7 @@ type buildFile struct { image string maintainer string config *Config + context string tmpContainers map[string]struct{} tmpImages map[string]struct{} @@ -168,6 +169,7 @@ func (b *buildFile) CmdInsert(args string) error { } defer file.Body.Close() + b.config.Cmd = []string{"echo", "INSERT", sourceUrl, "in", destPath} cid, err := b.run() if err != nil { return err @@ -185,6 +187,36 @@ func (b *buildFile) CmdInsert(args string) error { return b.commit(cid) } +func (b *buildFile) CmdAdd(args string) error { + tmp := strings.SplitN(args, " ", 2) + if len(tmp) != 2 { + return fmt.Errorf("Invalid INSERT format") + } + orig := strings.Trim(tmp[0], " ") + dest := strings.Trim(tmp[1], " ") + + b.config.Cmd = []string{"echo", "PUSH", orig, "in", dest} + cid, err := b.run() + if err != nil { + return err + } + + container := b.runtime.Get(cid) + if container == nil { + return fmt.Errorf("Error while creating the container (CmdAdd)") + } + + if err := os.MkdirAll(path.Join(container.rwPath(), dest), 0700); err != nil { + return err + } + + if err := utils.CopyDirectory(path.Join(b.context, orig), path.Join(container.rwPath(), dest)); err != nil { + return err + } + + return b.commit(cid) +} + func (b *buildFile) run() (string, error) { if b.image == "" { return "", fmt.Errorf("Please provide a source image with `from` prior to run") @@ -216,7 +248,6 @@ func (b *buildFile) commit(id string) error { return fmt.Errorf("Please provide a source image with `from` prior to commit") } b.config.Image = b.image - if id == "" { cmd := b.config.Cmd b.config.Cmd = []string{"true"} @@ -245,9 +276,19 @@ func (b *buildFile) commit(id string) error { } func (b *buildFile) Build(dockerfile, context io.Reader) (string, error) { - b.out = os.Stdout - defer b.clearTmp(b.tmpContainers, b.tmpImages) + + if context != nil { + name, err := ioutil.TempDir("/tmp", "docker-build") + if err != nil { + return "", err + } + if err := Untar(context, name); err != nil { + return "", err + } + defer os.RemoveAll(name) + b.context = name + } file := bufio.NewReader(dockerfile) for { line, err := file.ReadString('\n') @@ -307,6 +348,7 @@ func NewBuildFile(srv *Server, out io.Writer) BuildFile { runtime: srv.runtime, srv: srv, config: &Config{}, + out: out, tmpContainers: make(map[string]struct{}), tmpImages: make(map[string]struct{}), } diff --git a/commands.go b/commands.go index f5c658e6b..79fdafe7d 100644 --- a/commands.go +++ b/commands.go @@ -189,35 +189,6 @@ func (cli *DockerCli) CmdBuild(args ...string) error { return nil } -func (cli *DockerCli) CmdBuildClient(args ...string) error { - cmd := Subcmd("build", "-|Dockerfile", "Build an image from Dockerfile or via stdin") - if err := cmd.Parse(args); err != nil { - return nil - } - var ( - file io.ReadCloser - err error - ) - - if cmd.NArg() == 0 { - file, err = os.Open("Dockerfile") - if err != nil { - return err - } - } else if cmd.Arg(0) == "-" { - file = os.Stdin - } else { - file, err = os.Open(cmd.Arg(0)) - if err != nil { - return err - } - } - if _, err := NewBuilderClient("0.0.0.0", 4243).Build(file, nil); err != nil { - return err - } - return nil -} - // 'docker login': login / register a user to registry service. func (cli *DockerCli) CmdLogin(args ...string) error { var readStringOnRawTerminal = func(stdin io.Reader, stdout io.Writer, echo bool) string { diff --git a/runtime_test.go b/runtime_test.go index 01bd2a012..9ca280495 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -32,13 +32,6 @@ func nuke(runtime *Runtime) error { return os.RemoveAll(runtime.root) } -func CopyDirectory(source, dest string) error { - if _, err := exec.Command("cp", "-ra", source, dest).Output(); err != nil { - return err - } - return nil -} - func layerArchive(tarfile string) (io.Reader, error) { // FIXME: need to close f somewhere f, err := os.Open(tarfile) @@ -88,7 +81,7 @@ func newTestRuntime() (*Runtime, error) { if err := os.Remove(root); err != nil { return nil, err } - if err := CopyDirectory(unitTestStoreBase, root); err != nil { + if err := utils.CopyDirectory(unitTestStoreBase, root); err != nil { return nil, err } @@ -345,7 +338,7 @@ func TestRestore(t *testing.T) { if err := os.Remove(root); err != nil { t.Fatal(err) } - if err := CopyDirectory(unitTestStoreBase, root); err != nil { + if err := utils.CopyDirectory(unitTestStoreBase, root); err != nil { t.Fatal(err) } diff --git a/utils/utils.go b/utils/utils.go index 150eae857..90ef30625 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -531,6 +531,13 @@ func GetKernelVersion() (*KernelVersionInfo, error) { }, nil } +func CopyDirectory(source, dest string) error { + if _, err := exec.Command("cp", "-ra", source, dest).Output(); err != nil { + return err + } + return nil +} + type NopFlusher struct{} func (f *NopFlusher) Flush() {} From 90ffcda05547332020ec6f2b98179380f7d0e56f Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 28 May 2013 13:38:40 -0700 Subject: [PATCH 79/95] Update the UI for docker build --- commands.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/commands.go b/commands.go index 79fdafe7d..cfe6c38a4 100644 --- a/commands.go +++ b/commands.go @@ -112,9 +112,8 @@ func (cli *DockerCli) CmdInsert(args ...string) error { } func (cli *DockerCli) CmdBuild(args ...string) error { - cmd := Subcmd("build", "[OPTIONS]", "Build an image from a Dockerfile") - fileName := cmd.String("f", "Dockerfile", "Use file as Dockerfile. Can be '-' for stdin") - contextPath := cmd.String("c", "", "Use the specified directory as context for the build") + cmd := Subcmd("build", "[OPTIONS] [CONTEXT]", "Build an image from a Dockerfile") + fileName := cmd.String("f", "Dockerfile", "Use `file` as Dockerfile. Can be '-' for stdin") if err := cmd.Parse(args); err != nil { return nil } @@ -146,14 +145,16 @@ func (cli *DockerCli) CmdBuild(args ...string) error { } multipartBody = io.MultiReader(multipartBody, file) + compression := Bzip2 + // Create a FormFile multipart for the context if needed - if *contextPath != "" { + if cmd.Arg(0) != "" { // FIXME: Use NewTempArchive in order to have the size and avoid too much memory usage? - context, err := Tar(*contextPath, Bzip2) + context, err := Tar(cmd.Arg(0), compression) if err != nil { return err } - if _, err := w.CreateFormFile("Context", *contextPath+".tar.bz2"); err != nil { + if _, err := w.CreateFormFile("Context", cmd.Arg(0)+"."+compression.Extension()); err != nil { return err } multipartBody = io.MultiReader(multipartBody, utils.ProgressReader(ioutil.NopCloser(context), -1, os.Stdout, "Uploading Context %v/%v (%v)")) @@ -165,6 +166,9 @@ func (cli *DockerCli) CmdBuild(args ...string) error { return err } req.Header.Set("Content-Type", w.FormDataContentType()) + if cmd.Arg(0) != "" { + req.Header.Set("X-Docker-Context-Compression", compression.Flag()) + } resp, err := http.DefaultClient.Do(req) if err != nil { From a48799016a43e6badae72e855f9a90592b6cdd98 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 28 May 2013 13:46:52 -0700 Subject: [PATCH 80/95] Fix merge issue --- api.go | 2 +- buildfile.go | 2 +- commands.go | 2 +- server.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api.go b/api.go index e004aa4a3..7b82135ef 100644 --- a/api.go +++ b/api.go @@ -626,7 +626,7 @@ func postImagesGetCache(srv *Server, version float64, w http.ResponseWriter, r * return nil } -func postBuild(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { +func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := r.ParseMultipartForm(4096); err != nil { return err } diff --git a/buildfile.go b/buildfile.go index 0cd8aa182..f1e08b20f 100644 --- a/buildfile.go +++ b/buildfile.go @@ -63,7 +63,7 @@ func (b *buildFile) CmdFrom(name string) error { remote = name } - if err := b.srv.ImagePull(remote, tag, "", b.out); err != nil { + if err := b.srv.ImagePull(remote, tag, "", b.out, false); err != nil { return err } diff --git a/commands.go b/commands.go index 952a2bb6c..a79a24bff 100644 --- a/commands.go +++ b/commands.go @@ -175,7 +175,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error { if _, err := w.CreateFormFile("Context", cmd.Arg(0)+"."+compression.Extension()); err != nil { return err } - multipartBody = io.MultiReader(multipartBody, utils.ProgressReader(ioutil.NopCloser(context), -1, os.Stdout, "Uploading Context %v/%v (%v)")) + multipartBody = io.MultiReader(multipartBody, utils.ProgressReader(ioutil.NopCloser(context), -1, os.Stdout, "Uploading Context %v/%v (%v)", false)) } // Send the multipart request with correct content-type diff --git a/server.go b/server.go index 0714cba54..245558780 100644 --- a/server.go +++ b/server.go @@ -92,7 +92,7 @@ func (srv *Server) ImageInsert(name, url, path string, out io.Writer) (string, e } if err := c.Inject(utils.ProgressReader(file.Body, int(file.ContentLength), out, "Downloading %v/%v (%v)\r", false), path); err != nil { - return err + return "", err } // FIXME: Handle custom repo, tag comment, author img, err = b.Commit(c, "", "", img.Comment, img.Author, nil) From 582a9e0a67598672db35ef26a18027dd6fb222ca Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 28 May 2013 13:47:04 -0700 Subject: [PATCH 81/95] Make docker build flush output each line --- api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api.go b/api.go index 7b82135ef..ca65c8e11 100644 --- a/api.go +++ b/api.go @@ -643,7 +643,7 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ } } - b := NewBuildFile(srv, w) + b := NewBuildFile(srv, utils.NewWriteFlusher(w)) if _, err := b.Build(file, context); err != nil { return err } From cfb8cbe5214c58690ca99cd44b25bd202c4dbcf7 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 28 May 2013 13:51:21 -0700 Subject: [PATCH 82/95] Small fix --- buildfile.go | 3 +++ commands.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/buildfile.go b/buildfile.go index f1e08b20f..88dcadbf9 100644 --- a/buildfile.go +++ b/buildfile.go @@ -188,6 +188,9 @@ func (b *buildFile) CmdInsert(args string) error { } func (b *buildFile) CmdAdd(args string) error { + if b.context == "" { + return fmt.Errorf("No context given. Impossible to use ADD") + } tmp := strings.SplitN(args, " ", 2) if len(tmp) != 2 { return fmt.Errorf("Invalid INSERT format") diff --git a/commands.go b/commands.go index a79a24bff..5d65daeb5 100644 --- a/commands.go +++ b/commands.go @@ -175,7 +175,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error { if _, err := w.CreateFormFile("Context", cmd.Arg(0)+"."+compression.Extension()); err != nil { return err } - multipartBody = io.MultiReader(multipartBody, utils.ProgressReader(ioutil.NopCloser(context), -1, os.Stdout, "Uploading Context %v/%v (%v)", false)) + multipartBody = io.MultiReader(multipartBody, utils.ProgressReader(ioutil.NopCloser(context), -1, os.Stdout, "Uploading Context %v/%v (%v)\r", false)) } // Send the multipart request with correct content-type From 387eb5295a9ea75a099dd36adcae18229541f613 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 28 May 2013 14:13:20 -0700 Subject: [PATCH 83/95] Removed deprecated SPECS directory --- SPECS/data-volumes.md | 71 ------------------------------------------- 1 file changed, 71 deletions(-) delete mode 100644 SPECS/data-volumes.md diff --git a/SPECS/data-volumes.md b/SPECS/data-volumes.md deleted file mode 100644 index d800656af..000000000 --- a/SPECS/data-volumes.md +++ /dev/null @@ -1,71 +0,0 @@ - -## Spec for data volumes - -Spec owner: Solomon Hykes - -Data volumes (issue #111) are a much-requested feature which trigger much discussion and debate. Below is the current authoritative spec for implementing data volumes. -This spec will be deprecated once the feature is fully implemented. - -Discussion, requests, trolls, demands, offerings, threats and other forms of supplications concerning this spec should be addressed to Solomon here: https://github.com/dotcloud/docker/issues/111 - - -### 1. Creating data volumes - -At container creation, parts of a container's filesystem can be mounted as separate data volumes. Volumes are defined with the -v flag. - -For example: - -```bash -$ docker run -v /var/lib/postgres -v /var/log postgres /usr/bin/postgres -``` - -In this example, a new container is created from the 'postgres' image. At the same time, docker creates 2 new data volumes: one will be mapped to the container at /var/lib/postgres, the other at /var/log. - -2 important notes: - -1) Volumes don't have top-level names. At no point does the user provide a name, or is a name given to him. Volumes are identified by the path at which they are mounted inside their container. - -2) The user doesn't choose the source of the volume. Docker only mounts volumes it created itself, in the same way that it only runs containers that it created itself. That is by design. - - -### 2. Sharing data volumes - -Instead of creating its own volumes, a container can share another container's volumes. For example: - -```bash -$ docker run --volumes-from $OTHER_CONTAINER_ID postgres /usr/local/bin/postgres-backup -``` - -In this example, a new container is created from the 'postgres' example. At the same time, docker will *re-use* the 2 data volumes created in the previous example. One volume will be mounted on the /var/lib/postgres of *both* containers, and the other will be mounted on the /var/log of both containers. - -### 3. Under the hood - -Docker stores volumes in /var/lib/docker/volumes. Each volume receives a globally unique ID at creation, and is stored at /var/lib/docker/volumes/ID. - -At creation, volumes are attached to a single container - the source of truth for this mapping will be the container's configuration. - -Mounting a volume consists of calling "mount --bind" from the volume's directory to the appropriate sub-directory of the container mountpoint. This may be done by Docker itself, or farmed out to lxc (which supports mount-binding) if possible. - - -### 4. Backups, transfers and other volume operations - -Volumes sometimes need to be backed up, transfered between hosts, synchronized, etc. These operations typically are application-specific or site-specific, eg. rsync vs. S3 upload vs. replication vs... - -Rather than attempting to implement all these scenarios directly, Docker will allow for custom implementations using an extension mechanism. - -### 5. Custom volume handlers - -Docker allows for arbitrary code to be executed against a container's volumes, to implement any custom action: backup, transfer, synchronization across hosts, etc. - -Here's an example: - -```bash -$ DB=$(docker run -d -v /var/lib/postgres -v /var/log postgres /usr/bin/postgres) - -$ BACKUP_JOB=$(docker run -d --volumes-from $DB shykes/backuper /usr/local/bin/backup-postgres --s3creds=$S3CREDS) - -$ docker wait $BACKUP_JOB -``` - -Congratulations, you just implemented a custom volume handler, using Docker's built-in ability to 1) execute arbitrary code and 2) share volumes between containers. - From 326faec6642896954ffbd407eeda7d19da193856 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 28 May 2013 14:57:36 -0700 Subject: [PATCH 84/95] De-duplicated contribution instructions. The authoritative instructions are in CONTRIBUTING.md at the root of the repo. --- CONTRIBUTING.md | 5 +- docs/sources/contributing/contributing.rst | 98 +--------------------- 2 files changed, 2 insertions(+), 101 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f461e9530..2e1141c30 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,9 +1,6 @@ # Contributing to Docker -Want to hack on Docker? Awesome! There are instructions to get you -started on the website: http://docker.io/gettingstarted.html - -They are probably not perfect, please let us know if anything feels +Want to hack on Docker? Awesome! Here are instructions to get you started. They are probably not perfect, please let us know if anything feels wrong or incomplete. ## Contribution guidelines diff --git a/docs/sources/contributing/contributing.rst b/docs/sources/contributing/contributing.rst index c2bd7c80f..25b4df763 100644 --- a/docs/sources/contributing/contributing.rst +++ b/docs/sources/contributing/contributing.rst @@ -5,101 +5,5 @@ Contributing to Docker ====================== -Want to hack on Docker? Awesome! There are instructions to get you -started on the website: http://docker.io/gettingstarted.html +Want to hack on Docker? Awesome! The repository includes `all the instructions you need to get started `. -They are probably not perfect, please let us know if anything feels -wrong or incomplete. - -Contribution guidelines ------------------------ - -Pull requests are always welcome -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -We are always thrilled to receive pull requests, and do our best to -process them as fast as possible. Not sure if that typo is worth a pull -request? Do it! We will appreciate it. - -If your pull request is not accepted on the first try, don't be -discouraged! If there's a problem with the implementation, hopefully you -received feedback on what to improve. - -We're trying very hard to keep Docker lean and focused. We don't want it -to do everything for everybody. This means that we might decide against -incorporating a new feature. However, there might be a way to implement -that feature *on top of* docker. - -Discuss your design on the mailing list -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -We recommend discussing your plans `on the mailing -list `__ -before starting to code - especially for more ambitious contributions. -This gives other contributors a chance to point you in the right -direction, give feedback on your design, and maybe point out if someone -else is working on the same thing. - -Create issues... -~~~~~~~~~~~~~~~~ - -Any significant improvement should be documented as `a github -issue `__ before anybody -starts working on it. - -...but check for existing issues first! -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Please take a moment to check that an issue doesn't already exist -documenting your bug report or improvement proposal. If it does, it -never hurts to add a quick "+1" or "I have this problem too". This will -help prioritize the most common problems and requests. - -Conventions -~~~~~~~~~~~ - -Fork the repo and make changes on your fork in a feature branch: - -- If it's a bugfix branch, name it XXX-something where XXX is the number of the - issue -- If it's a feature branch, create an enhancement issue to announce your - intentions, and name it XXX-something where XXX is the number of the issue. - -Submit unit tests for your changes. Go has a great test framework built in; use -it! Take a look at existing tests for inspiration. Run the full test suite on -your branch before submitting a pull request. - -Make sure you include relevant updates or additions to documentation when -creating or modifying features. - -Write clean code. Universally formatted code promotes ease of writing, reading, -and maintenance. Always run ``go fmt`` before committing your changes. Most -editors have plugins that do this automatically, and there's also a git -pre-commit hook: - -.. code-block:: bash - - curl -o .git/hooks/pre-commit https://raw.github.com/edsrzf/gofmt-git-hook/master/fmt-check && chmod +x .git/hooks/pre-commit - - -Pull requests descriptions should be as clear as possible and include a -reference to all the issues that they address. - -Code review comments may be added to your pull request. Discuss, then make the -suggested modifications and push additional commits to your feature branch. Be -sure to post a comment after pushing. The new commits will show up in the pull -request automatically, but the reviewers will not be notified unless you -comment. - -Before the pull request is merged, make sure that you squash your commits into -logical units of work using ``git rebase -i`` and ``git push -f``. After every -commit the test suite should be passing. Include documentation changes in the -same commit so that a revert would remove all traces of the feature or fix. - -Commits that fix or close an issue should include a reference like ``Closes #XXX`` -or ``Fixes #XXX``, which will automatically close the issue when merged. - -Add your name to the AUTHORS file, but make sure the list is sorted and your -name and email address match your git configuration. The AUTHORS file is -regenerated occasionally from the git commit history, so a mismatch may result -in your changes being overwritten. From fe0c0c208c0e816419b668a6fd6567520698c2d2 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 28 May 2013 15:21:06 -0700 Subject: [PATCH 85/95] Send error without headers when using chunks --- api.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api.go b/api.go index ca65c8e11..12abb3da2 100644 --- a/api.go +++ b/api.go @@ -631,7 +631,7 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ return err } - file, _, err := r.FormFile("Dockerfile") + dockerfile, _, err := r.FormFile("Dockerfile") if err != nil { return err } @@ -644,8 +644,8 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ } b := NewBuildFile(srv, utils.NewWriteFlusher(w)) - if _, err := b.Build(file, context); err != nil { - return err + if _, err := b.Build(dockerfile, context); err != nil { + fmt.Fprintf(w, "Error build: %s\n", err) } return nil } From 2897cb04760d7e4e7e52ccc20e94c94e3743667e Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 28 May 2013 15:22:01 -0700 Subject: [PATCH 86/95] Add directory contents instead of while directory for docker build --- buildfile.go | 21 ++++++++++++++++++++- utils/utils.go | 10 ++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/buildfile.go b/buildfile.go index 88dcadbf9..15577b98e 100644 --- a/buildfile.go +++ b/buildfile.go @@ -213,9 +213,28 @@ func (b *buildFile) CmdAdd(args string) error { return err } - if err := utils.CopyDirectory(path.Join(b.context, orig), path.Join(container.rwPath(), dest)); err != nil { + origPath := path.Join(b.context, orig) + destPath := path.Join(container.rwPath(), dest) + + fi, err := os.Stat(origPath) + if err != nil { return err } + if fi.IsDir() { + files, err := ioutil.ReadDir(path.Join(b.context, orig)) + if err != nil { + return err + } + for _, fi := range files { + if err := utils.CopyDirectory(path.Join(origPath, fi.Name()), path.Join(destPath, fi.Name())); err != nil { + return err + } + } + } else { + if err := utils.CopyDirectory(origPath, destPath); err != nil { + return err + } + } return b.commit(cid) } diff --git a/utils/utils.go b/utils/utils.go index ac0a142ae..97bdea9e9 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -69,7 +69,7 @@ type progressReader struct { readProgress int // How much has been read so far (bytes) lastUpdate int // How many bytes read at least update template string // Template to print. Default "%v/%v (%v)" - json bool + json bool } func (r *progressReader) Read(p []byte) (n int, err error) { @@ -102,7 +102,7 @@ func (r *progressReader) Close() error { return io.ReadCloser(r.reader).Close() } func ProgressReader(r io.ReadCloser, size int, output io.Writer, template string, json bool) *progressReader { - if template == "" { + if template == "" { template = "%v/%v (%v)\r" } return &progressReader{r, NewWriteFlusher(output), size, 0, 0, template, json} @@ -533,8 +533,8 @@ func GetKernelVersion() (*KernelVersionInfo, error) { } func CopyDirectory(source, dest string) error { - if _, err := exec.Command("cp", "-ra", source, dest).Output(); err != nil { - return err + if output, err := exec.Command("cp", "-ra", source, dest).CombinedOutput(); err != nil { + return fmt.Errorf("Error copy: %s (%s)", err, output) } return nil } @@ -577,5 +577,3 @@ func FormatProgress(str string, json bool) string { } return "Downloading " + str + "\r" } - - From 2127f8d6ad091d699d3462715305a0f64340eca1 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 28 May 2013 15:22:34 -0700 Subject: [PATCH 87/95] Fill the multipart writer directly instead of using reader --- commands.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/commands.go b/commands.go index 5d65daeb5..bca825925 100644 --- a/commands.go +++ b/commands.go @@ -158,10 +158,12 @@ func (cli *DockerCli) CmdBuild(args ...string) error { } defer file.Close() } - if _, err := w.CreateFormFile("Dockerfile", *fileName); err != nil { + if wField, err := w.CreateFormFile("Dockerfile", *fileName); err != nil { return err + } else { + io.Copy(wField, file) } - multipartBody = io.MultiReader(multipartBody, file) + multipartBody = io.MultiReader(multipartBody, boundary) compression := Bzip2 @@ -172,20 +174,30 @@ func (cli *DockerCli) CmdBuild(args ...string) error { if err != nil { return err } - if _, err := w.CreateFormFile("Context", cmd.Arg(0)+"."+compression.Extension()); err != nil { + // NOTE: Do this in case '.' or '..' is input + absPath, err := filepath.Abs(cmd.Arg(0)) + if err != nil { return err } - multipartBody = io.MultiReader(multipartBody, utils.ProgressReader(ioutil.NopCloser(context), -1, os.Stdout, "Uploading Context %v/%v (%v)\r", false)) + if wField, err := w.CreateFormFile("Context", filepath.Base(absPath)+"."+compression.Extension()); err != nil { + return err + } else { + // FIXME: Find a way to have a progressbar for the upload too + io.Copy(wField, utils.ProgressReader(ioutil.NopCloser(context), -1, os.Stdout, "Caching Context %v/%v (%v)\r", false)) + } + + multipartBody = io.MultiReader(multipartBody, boundary) } // Send the multipart request with correct content-type - req, err := http.NewRequest("POST", fmt.Sprintf("http://%s:%d%s", cli.host, cli.port, "/build"), io.MultiReader(multipartBody, boundary)) + req, err := http.NewRequest("POST", fmt.Sprintf("http://%s:%d%s", cli.host, cli.port, "/build"), multipartBody) if err != nil { return err } req.Header.Set("Content-Type", w.FormDataContentType()) if cmd.Arg(0) != "" { req.Header.Set("X-Docker-Context-Compression", compression.Flag()) + fmt.Println("Uploading Context...") } resp, err := http.DefaultClient.Do(req) From 5b33b2463a27aa3356a4b6200cf4b81dd83c26a0 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 28 May 2013 15:31:06 -0700 Subject: [PATCH 88/95] Readd build tests --- buildfile_test.go | 72 +++++++++++++++++++++++++++++++++++++++++++++++ runtime_test.go | 1 - 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 buildfile_test.go diff --git a/buildfile_test.go b/buildfile_test.go new file mode 100644 index 000000000..b6f4e62ae --- /dev/null +++ b/buildfile_test.go @@ -0,0 +1,72 @@ +package docker + +import ( + "github.com/dotcloud/docker/utils" + "strings" + "testing" +) + +const Dockerfile = ` +# VERSION 0.1 +# DOCKER-VERSION 0.2 + +from ` + unitTestImageName + ` +run sh -c 'echo root:testpass > /tmp/passwd' +run mkdir -p /var/run/sshd +` + +func TestBuild(t *testing.T) { + runtime, err := newTestRuntime() + if err != nil { + t.Fatal(err) + } + defer nuke(runtime) + + srv := &Server{runtime: runtime} + + buildfile := NewBuildFile(srv, &utils.NopWriter{}) + + imgId, err := buildfile.Build(strings.NewReader(Dockerfile), nil) + if err != nil { + t.Fatal(err) + } + + builder := NewBuilder(runtime) + container, err := builder.Create( + &Config{ + Image: imgId, + Cmd: []string{"cat", "/tmp/passwd"}, + }, + ) + if err != nil { + t.Fatal(err) + } + defer runtime.Destroy(container) + + output, err := container.Output() + if err != nil { + t.Fatal(err) + } + if string(output) != "root:testpass\n" { + t.Fatalf("Unexpected output. Read '%s', expected '%s'", output, "root:testpass\n") + } + + container2, err := builder.Create( + &Config{ + Image: imgId, + Cmd: []string{"ls", "-d", "/var/run/sshd"}, + }, + ) + if err != nil { + t.Fatal(err) + } + defer runtime.Destroy(container2) + + output, err = container2.Output() + if err != nil { + t.Fatal(err) + } + if string(output) != "/var/run/sshd\n" { + t.Fatal("/var/run/sshd has not been created") + } +} diff --git a/runtime_test.go b/runtime_test.go index 27db53a88..55671e12b 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -8,7 +8,6 @@ import ( "io/ioutil" "net" "os" - "os/exec" "os/user" "sync" "testing" From 54af0536232ca71d37f7c6440f1bb17b3ed112db Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 28 May 2013 15:40:22 -0700 Subject: [PATCH 89/95] Make sure the last line of docker build is the image id --- buildfile.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildfile.go b/buildfile.go index 15577b98e..23f2f4717 100644 --- a/buildfile.go +++ b/buildfile.go @@ -355,7 +355,7 @@ func (b *buildFile) Build(dockerfile, context io.Reader) (string, error) { for i := range b.tmpImages { delete(b.tmpImages, i) } - fmt.Fprintf(b.out, "Build finished. image id: %s\n", b.image) + fmt.Fprintf(b.out, "Build success.\n Image id:\n%s\n", b.image) return b.image, nil } for i := range b.tmpContainers { From 24ddfe3f25f99db5a23f62d411c949b2236288a1 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 28 May 2013 19:39:09 -0700 Subject: [PATCH 90/95] Documented who decides what and how. --- AUTHORS | 5 +++ CONTRIBUTING.md | 69 ++++++++++++++++++++++++++++++++ MAINTAINERS | 2 + auth/MAINTAINERS | 1 + contrib/MAINTAINERS | 1 + contrib/docker-build/MAINTAINERS | 1 + docs/MAINTAINERS | 2 + docs/sources/api/MAINTAINERS | 1 + docs/theme/MAINTAINERS | 1 + docs/website/MAINTAINERS | 1 + packaging/MAINTAINERS | 1 + registry/MAINTAINERS | 3 ++ testing/MAINTAINERS | 1 + 13 files changed, 89 insertions(+) create mode 100644 MAINTAINERS create mode 120000 auth/MAINTAINERS create mode 100644 contrib/MAINTAINERS create mode 100644 contrib/docker-build/MAINTAINERS create mode 100644 docs/MAINTAINERS create mode 100644 docs/sources/api/MAINTAINERS create mode 100644 docs/theme/MAINTAINERS create mode 100644 docs/website/MAINTAINERS create mode 100644 packaging/MAINTAINERS create mode 100644 registry/MAINTAINERS create mode 100644 testing/MAINTAINERS diff --git a/AUTHORS b/AUTHORS index e7c6834cf..fdddedde1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,3 +1,8 @@ +# This file lists all individuals having contributed content to the repository. +# If you're submitting a patch, please add your name here in alphabetical order as part of the patch. +# +# For a list of active project maintainers, see the MAINTAINERS file. +# Al Tobey Alexey Shamrin Andrea Luzzardi diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2e1141c30..1b3c63e7d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -88,3 +88,72 @@ Add your name to the AUTHORS file, but make sure the list is sorted and your name and email address match your git configuration. The AUTHORS file is regenerated occasionally from the git commit history, so a mismatch may result in your changes being overwritten. + + +## Decision process + +### How are decisions made? + +Short answer: with pull requests to the docker repository. + +Docker is an open-source project with an open design philosophy. This means that the repository is the source of truth for EVERY aspect of the project, +including its philosophy, design, roadmap and APIs. *If it's part of the project, it's in the repo. It's in the repo, it's part of the project.* + +As a result, all decisions can be expressed as changes to the repository. An implementation change is a change to the source code. An API change is a change to +the API specification. A philosophy change is a change to the philosophy manifesto. And so on. + +All decisions affecting docker, big and small, follow the same 3 steps: + +* Step 1: Open a pull request. Anyone can do this. + +* Step 2: Discuss the pull request. Anyone can do this. + +* Step 3: Accept or refuse a pull request. The relevant maintainer does this (see below "Who decides what?") + + +### Who decides what? + +So all decisions are pull requests, and the relevant maintainer makes the decision by accepting or refusing the pull request. +But how do we identify the relevant maintainer for a given pull request? + +Docker follows the timeless, highly efficient and totally unfair system known as [Benevolent dictator for life](http://en.wikipedia.org/wiki/Benevolent_Dictator_for_Life), +with yours truly, Solomon Hykes, in the role of BDFL. +This means that all decisions are made by default by me. Since making every decision myself would be highly unscalable, in practice decisions are spread across multiple maintainers. + +The relevant maintainer for a pull request is assigned in 3 steps: + +* Step 1: Determine the subdirectory affected by the pull request. This might be src/registry, docs/source/api, or any other part of the repo. + +* Step 2: Find the MAINTAINERS file which affects this directory. If the directory itself does not have a MAINTAINERS file, work your way up the the repo hierarchy until you find one. + +* Step 3: The first maintainer listed is the primary maintainer. The pull request is assigned to him. He may assign it to other listed maintainers, at his discretion. + + +### I'm a maintainer, should I make pull requests too? + +Primary maintainers are not required to create pull requests when changing their own subdirectory, but secondary maintainers are. + +### Who assigns maintainers? + +Solomon. + +### How can I become a maintainer? + +Step 1: learn the component inside out +Step 2: make yourself useful by contributing code, bugfixes, support etc. +Step 3: volunteer on the irc channel (#docker@freenode) + +Don't forget: being a maintainer is a time investment. Make sure you will have time to make yourself available. +You don't have to be a maintainer to make a difference on the project! + +### What are a maintainer's responsibility? + +It is every maintainer's responsibility to: + a) be aware of which pull requests they must review, and do so quickly + b) communicate clearly and transparently with other maintainers + c) be available to anyone with questions, bug reports, criticism etc. on their component. This includes irc, github requests and the mailing list. + d) make sure they respect the philosophy and design of the project + +### How is this process changed? + +Just like everything else: by making a pull request :) diff --git a/MAINTAINERS b/MAINTAINERS new file mode 100644 index 000000000..a89240932 --- /dev/null +++ b/MAINTAINERS @@ -0,0 +1,2 @@ +Solomon Hykes +Guillaume Charmes diff --git a/auth/MAINTAINERS b/auth/MAINTAINERS new file mode 120000 index 000000000..dcaec6ec4 --- /dev/null +++ b/auth/MAINTAINERS @@ -0,0 +1 @@ +../registry/MAINTAINERS \ No newline at end of file diff --git a/contrib/MAINTAINERS b/contrib/MAINTAINERS new file mode 100644 index 000000000..0b7931f90 --- /dev/null +++ b/contrib/MAINTAINERS @@ -0,0 +1 @@ +# Maintainer wanted! Enroll on #docker@freenode diff --git a/contrib/docker-build/MAINTAINERS b/contrib/docker-build/MAINTAINERS new file mode 100644 index 000000000..e1c6f2ccf --- /dev/null +++ b/contrib/docker-build/MAINTAINERS @@ -0,0 +1 @@ +Solomon Hykes diff --git a/docs/MAINTAINERS b/docs/MAINTAINERS new file mode 100644 index 000000000..f079e5848 --- /dev/null +++ b/docs/MAINTAINERS @@ -0,0 +1,2 @@ +Andy Rothfusz +Ken Cochrane diff --git a/docs/sources/api/MAINTAINERS b/docs/sources/api/MAINTAINERS new file mode 100644 index 000000000..e1c6f2ccf --- /dev/null +++ b/docs/sources/api/MAINTAINERS @@ -0,0 +1 @@ +Solomon Hykes diff --git a/docs/theme/MAINTAINERS b/docs/theme/MAINTAINERS new file mode 100644 index 000000000..6df367c07 --- /dev/null +++ b/docs/theme/MAINTAINERS @@ -0,0 +1 @@ +Thatcher Penskens diff --git a/docs/website/MAINTAINERS b/docs/website/MAINTAINERS new file mode 100644 index 000000000..6df367c07 --- /dev/null +++ b/docs/website/MAINTAINERS @@ -0,0 +1 @@ +Thatcher Penskens diff --git a/packaging/MAINTAINERS b/packaging/MAINTAINERS new file mode 100644 index 000000000..228bd562e --- /dev/null +++ b/packaging/MAINTAINERS @@ -0,0 +1 @@ +Daniel Mizyrycki diff --git a/registry/MAINTAINERS b/registry/MAINTAINERS new file mode 100644 index 000000000..b11dfc061 --- /dev/null +++ b/registry/MAINTAINERS @@ -0,0 +1,3 @@ +Sam Alba +Joffrey Fuhrer +Ken Cochrane diff --git a/testing/MAINTAINERS b/testing/MAINTAINERS new file mode 100644 index 000000000..228bd562e --- /dev/null +++ b/testing/MAINTAINERS @@ -0,0 +1 @@ +Daniel Mizyrycki From 7181edf4b2fe17791cc4f843271d9c7fce0f14f3 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 28 May 2013 20:44:41 -0700 Subject: [PATCH 91/95] getmaintainer.sh: parse MAINTAINERS file to determine who should review changes to a particular file or directory --- hack/getmaintainer.sh | 58 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 hack/getmaintainer.sh diff --git a/hack/getmaintainer.sh b/hack/getmaintainer.sh new file mode 100755 index 000000000..2c24bacc8 --- /dev/null +++ b/hack/getmaintainer.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +if [ $# -ne 1 ]; then + echo >&2 "Usage: $0 PATH" + echo >&2 "Show the primary and secondary maintainers for a given path" + exit 1 +fi + +set -e + +DEST=$1 +DESTFILE="" +if [ ! -d $DEST ]; then + DESTFILE=$(basename $DEST) + DEST=$(dirname $DEST) +fi + +MAINTAINERS=() +cd $DEST +while true; do + if [ -e ./MAINTAINERS ]; then + { + while read line; do + re='^([^:]*): *(.*)$' + file=$(echo $line | sed -E -n "s/$re/\1/p") + if [ ! -z "$file" ]; then + if [ "$file" = "$DESTFILE" ]; then + echo "Override: $line" + maintainer=$(echo $line | sed -E -n "s/$re/\2/p") + MAINTAINERS=("$maintainer" "${MAINTAINERS[@]}") + fi + else + MAINTAINERS+=("$line"); + fi + done; + } < MAINTAINERS + fi + if [ -d .git ]; then + break + fi + if [ "$(pwd)" = "/" ]; then + break + fi + cd .. +done + +PRIMARY="${MAINTAINERS[0]}" +PRIMARY_FIRSTNAME=$(echo $PRIMARY | cut -d' ' -f1) + +firstname() { + echo $1 | cut -d' ' -f1 +} + +echo "--- $PRIMARY is the PRIMARY MAINTAINER of $1. Assign pull requests to him." +echo "$(firstname $PRIMARY) may assign pull requests to the following secondary maintainers:" +for SECONDARY in "${MAINTAINERS[@]:1}"; do + echo "--- $SECONDARY" +done From aa42c6f2a284c1095ba65866aa8c28f3e5c31fcd Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 28 May 2013 20:45:12 -0700 Subject: [PATCH 92/95] Added Victor and Daniel as maintainers for api.go and Vagrantfile, respectively --- MAINTAINERS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index a89240932..6203feeb0 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1,2 +1,4 @@ Solomon Hykes Guillaume Charmes +api.go: Victor Vieux +Vagrantfile: Daniel Mizyrycki From 286ce266b4415ae27d5d9cc177ad12db44845a84 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 28 May 2013 20:55:07 -0700 Subject: [PATCH 93/95] allmaintainers.sh: print a flat list of all maintainers of a directory (including sub-directories) --- hack/allmaintainers.sh | 3 +++ 1 file changed, 3 insertions(+) create mode 100755 hack/allmaintainers.sh diff --git a/hack/allmaintainers.sh b/hack/allmaintainers.sh new file mode 100755 index 000000000..1ea5a9f74 --- /dev/null +++ b/hack/allmaintainers.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +find $1 -name MAINTAINERS -exec cat {} ';' | sed -E -e 's/^[^:]*: *(.*)$/\1/' | grep -E -v -e '^ *$' -e '^ *#.*$' | sort -u From 3bac27f2405c746c068dbe31f8f205472d0f1b03 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 28 May 2013 22:26:42 -0600 Subject: [PATCH 94/95] Fixed formatting of CONTRIBUTING.md --- CONTRIBUTING.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1b3c63e7d..84c854007 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -139,9 +139,9 @@ Solomon. ### How can I become a maintainer? -Step 1: learn the component inside out -Step 2: make yourself useful by contributing code, bugfixes, support etc. -Step 3: volunteer on the irc channel (#docker@freenode) +* Step 1: learn the component inside out +* Step 2: make yourself useful by contributing code, bugfixes, support etc. +* Step 3: volunteer on the irc channel (#docker@freenode) Don't forget: being a maintainer is a time investment. Make sure you will have time to make yourself available. You don't have to be a maintainer to make a difference on the project! @@ -149,10 +149,11 @@ You don't have to be a maintainer to make a difference on the project! ### What are a maintainer's responsibility? It is every maintainer's responsibility to: - a) be aware of which pull requests they must review, and do so quickly - b) communicate clearly and transparently with other maintainers - c) be available to anyone with questions, bug reports, criticism etc. on their component. This includes irc, github requests and the mailing list. - d) make sure they respect the philosophy and design of the project + +# Be aware of which pull requests they must review, and do so quickly +# Communicate clearly and transparently with other maintainers +# Be available to anyone with questions, bug reports, criticism etc. on their component. This includes irc, github requests and the mailing list. +# Make sure they respect the philosophy and design of the project ### How is this process changed? From dc1fa0745f779d8c9a513dea71021d263b89ca5f Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 28 May 2013 22:33:48 -0600 Subject: [PATCH 95/95] Improved wording of a maintainer's responsibilities --- CONTRIBUTING.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 84c854007..7d90e28ca 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -150,10 +150,10 @@ You don't have to be a maintainer to make a difference on the project! It is every maintainer's responsibility to: -# Be aware of which pull requests they must review, and do so quickly -# Communicate clearly and transparently with other maintainers -# Be available to anyone with questions, bug reports, criticism etc. on their component. This includes irc, github requests and the mailing list. -# Make sure they respect the philosophy and design of the project +* 1) Expose a clear roadmap for improving their component. +* 2) Deliver prompt feedback and decisions on pull requests. +* 3) Be available to anyone with questions, bug reports, criticism etc. on their component. This includes irc, github requests and the mailing list. +* 4) Make sure their component respects the philosophy, design and roadmap of the project. ### How is this process changed?