From f9a9fed08f41e97e06fe92cab2f6c267331bfec3 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Mon, 6 May 2013 17:00:21 -0600 Subject: [PATCH 01/61] Update mkimage-debian.sh now that wheezy is officially the stable release - also, we can't rely on "release" versions for testing or unstable - only "stable" has reliable release versions Upstream-commit: 2f89315bf882f6b507f843a65fcf08ba2ae91959 Component: engine --- components/engine/contrib/mkimage-debian.sh | 22 ++++++++------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/components/engine/contrib/mkimage-debian.sh b/components/engine/contrib/mkimage-debian.sh index ace555ada6..89349e4acc 100755 --- a/components/engine/contrib/mkimage-debian.sh +++ b/components/engine/contrib/mkimage-debian.sh @@ -2,18 +2,15 @@ set -e # these should match the names found at http://www.debian.org/releases/ -stableSuite='squeeze' -testingSuite='wheezy' +stableSuite='wheezy' +testingSuite='jessie' unstableSuite='sid' -# if suite is equal to this, it gets the "latest" tag -latestSuite="$testingSuite" - variant='minbase' include='iproute,iputils-ping' repo="$1" -suite="${2:-$latestSuite}" +suite="${2:-$stableSuite}" mirror="${3:-}" # stick to the default debootstrap mirror if one is not provided if [ ! "$repo" ]; then @@ -41,17 +38,14 @@ img=$(sudo tar -c . | docker import -) # tag suite docker tag $img $repo $suite -if [ "$suite" = "$latestSuite" ]; then - # tag latest - docker tag $img $repo latest -fi - # test the image docker run -i -t $repo:$suite echo success -# unstable's version numbers match testing (since it's mostly just a sandbox for testing), so it doesn't get a version number tag -if [ "$suite" != "$unstableSuite" -a "$suite" != 'unstable' ]; then - # tag the specific version +if [ "$suite" = "$stableSuite" -o "$suite" = 'stable' ]; then + # tag latest + docker tag $img $repo latest + + # tag the specific debian release version ver=$(docker run $repo:$suite cat /etc/debian_version) docker tag $img $repo $ver fi From 39f3a9ee0e553d7baca66776a4c4d3a08f6611ac Mon Sep 17 00:00:00 2001 From: unclejack Date: Fri, 24 May 2013 21:40:56 +0300 Subject: [PATCH 02/61] add arch field to image struct Upstream-commit: 2cf92abf0eff49b21812d88e74813b8848f9b758 Component: engine --- components/engine/image.go | 1 + 1 file changed, 1 insertion(+) diff --git a/components/engine/image.go b/components/engine/image.go index 342c0c94b7..d825b4bba2 100644 --- a/components/engine/image.go +++ b/components/engine/image.go @@ -27,6 +27,7 @@ type Image struct { DockerVersion string `json:"docker_version,omitempty"` Author string `json:"author,omitempty"` Config *Config `json:"config,omitempty"` + Architecture string `json:"architecture,omitempty"` graph *Graph } From 03c163a915fbfd3dea45e6dbe8c305b8a3260f2f Mon Sep 17 00:00:00 2001 From: unclejack Date: Fri, 24 May 2013 21:42:09 +0300 Subject: [PATCH 03/61] set architecture to x86_64 by default We're going to hardcode architecture to amd64 for now. This is a stub and will have to be changed to set the actual arch. Upstream-commit: 5f69a53dba4b0e550ab29c7f2bf4277222927097 Component: engine --- components/engine/graph.go | 1 + 1 file changed, 1 insertion(+) diff --git a/components/engine/graph.go b/components/engine/graph.go index 5bf305fc22..6010c9b6ca 100644 --- a/components/engine/graph.go +++ b/components/engine/graph.go @@ -107,6 +107,7 @@ func (graph *Graph) Create(layerData Archive, container *Container, comment, aut DockerVersion: VERSION, Author: author, Config: config, + Architecture: "x86_64", } if container != nil { img.Parent = container.Image From 7a922259e1440a8d4f5fe7a9d722a6fc4004162d Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Sat, 25 May 2013 14:12:02 +0000 Subject: [PATCH 04/61] add error handling Upstream-commit: cb0bc4adc297baeea8e7b74269765c35457e04e7 Component: engine --- components/engine/api.go | 3 ++- components/engine/commands.go | 3 +++ components/engine/utils/utils.go | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/components/engine/api.go b/components/engine/api.go index 3164a886f6..e5816b255f 100644 --- a/components/engine/api.go +++ b/components/engine/api.go @@ -295,7 +295,8 @@ func postImagesCreate(srv *Server, version float64, w http.ResponseWriter, r *ht w.Header().Set("Content-Type", "application/json") } if err := srv.ImagePull(image, tag, registry, w, version > 1.0); err != nil { - return err + fmt.Fprintf(w, utils.FormatError(err.Error(), version > 1.0)) + return nil } } else { //import if err := srv.ImageImport(src, repo, tag, r.Body, w); err != nil { diff --git a/components/engine/commands.go b/components/engine/commands.go index 6c4dcd14d6..01ab8a334f 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -1261,6 +1261,7 @@ func (cli *DockerCli) stream(method, path string, in io.Reader, out io.Writer) e type Message struct { Status string `json:"status,omitempty"` Progress string `json:"progress,omitempty"` + Error string `json:"error,omitempty"` } dec := json.NewDecoder(resp.Body) for { @@ -1272,6 +1273,8 @@ func (cli *DockerCli) stream(method, path string, in io.Reader, out io.Writer) e } if m.Progress != "" { fmt.Fprintf(out, "Downloading %s\r", m.Progress) + } else if m.Error != "" { + return fmt.Errorf(m.Error) } else { fmt.Fprintf(out, "%s\n", m.Status) } diff --git a/components/engine/utils/utils.go b/components/engine/utils/utils.go index 233c624b68..8588c52478 100644 --- a/components/engine/utils/utils.go +++ b/components/engine/utils/utils.go @@ -564,6 +564,13 @@ func FormatStatus(str string, json bool) string { return str + "\r\n" } +func FormatError(str string, json bool) string { + if json { + return "{\"error\" : \"" + str + "\"}" + } + return "Error: " + str + "\r\n" +} + func FormatProgress(str string, json bool) string { if json { return "{\"progress\" : \"" + str + "\"}" From 04ca200a24d2ee9076f6d9f4c6d58fa879b35dff Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Sat, 25 May 2013 15:09:46 +0000 Subject: [PATCH 05/61] imporved error, push, import insert Upstream-commit: c8c7094b2e8088210e2182e582264e09222c6e3d Component: engine --- components/engine/api.go | 44 ++++++++++++++----- components/engine/graph.go | 2 +- components/engine/runtime_test.go | 2 +- components/engine/server.go | 72 +++++++++++++++---------------- components/engine/utils/utils.go | 44 +++++++++++++------ 5 files changed, 101 insertions(+), 63 deletions(-) diff --git a/components/engine/api.go b/components/engine/api.go index e5816b255f..55fb8d5a66 100644 --- a/components/engine/api.go +++ b/components/engine/api.go @@ -289,17 +289,25 @@ func postImagesCreate(srv *Server, version float64, w http.ResponseWriter, r *ht tag := r.Form.Get("tag") repo := r.Form.Get("repo") + if version > 1.0 { + w.Header().Set("Content-Type", "application/json") + } + sf := utils.NewStreamFormatter(version > 1.0) if image != "" { //pull registry := r.Form.Get("registry") - if version > 1.0 { - w.Header().Set("Content-Type", "application/json") - } - if err := srv.ImagePull(image, tag, registry, w, version > 1.0); err != nil { - fmt.Fprintf(w, utils.FormatError(err.Error(), version > 1.0)) - return nil + if err := srv.ImagePull(image, tag, registry, w, sf); err != nil { + if sf.Used() { + fmt.Fprintf(w, sf.FormatError(err)) + return nil + } + return err } } else { //import - if err := srv.ImageImport(src, repo, tag, r.Body, w); err != nil { + if err := srv.ImageImport(src, repo, tag, r.Body, w, sf); err != nil { + if sf.Used() { + fmt.Fprintf(w, sf.FormatError(err)) + return nil + } return err } } @@ -335,8 +343,15 @@ func postImagesInsert(srv *Server, version float64, w http.ResponseWriter, r *ht return fmt.Errorf("Missing parameter") } name := vars["name"] - - if err := srv.ImageInsert(name, url, path, w); err != nil { + if version > 1.0 { + w.Header().Set("Content-Type", "application/json") + } + sf := utils.NewStreamFormatter(version > 1.0) + if err := srv.ImageInsert(name, url, path, w, sf); err != nil { + if sf.Used() { + fmt.Fprintf(w, sf.FormatError(err)) + return nil + } return err } return nil @@ -352,8 +367,15 @@ func postImagesPush(srv *Server, version float64, w http.ResponseWriter, r *http return fmt.Errorf("Missing parameter") } name := vars["name"] - - if err := srv.ImagePush(name, registry, w); err != nil { + if version > 1.0 { + w.Header().Set("Content-Type", "application/json") + } + sf := utils.NewStreamFormatter(version > 1.0) + if err := srv.ImagePush(name, registry, w, sf); err != nil { + if sf.Used() { + fmt.Fprintf(w, sf.FormatError(err)) + return nil + } return err } return nil diff --git a/components/engine/graph.go b/components/engine/graph.go index c0dd869227..0090d51636 100644 --- a/components/engine/graph.go +++ b/components/engine/graph.go @@ -165,7 +165,7 @@ func (graph *Graph) TempLayerArchive(id string, compression Compression, output if err != nil { return nil, err } - return NewTempArchive(utils.ProgressReader(ioutil.NopCloser(archive), 0, output, "Buffering to disk %v/%v (%v)", false), tmp.Root) + return NewTempArchive(utils.ProgressReader(ioutil.NopCloser(archive), 0, output, "Buffering to disk %v/%v (%v)", utils.NewStreamFormatter(false)), tmp.Root) } // Mktemp creates a temporary sub-directory inside the graph's filesystem. diff --git a/components/engine/runtime_test.go b/components/engine/runtime_test.go index 6c4ec5ded4..0dd71c48a3 100644 --- a/components/engine/runtime_test.go +++ b/components/engine/runtime_test.go @@ -75,7 +75,7 @@ func init() { registry: registry.NewRegistry(runtime.root), } // Retrieve the Image - if err := srv.ImagePull(unitTestImageName, "", "", os.Stdout, false); err != nil { + if err := srv.ImagePull(unitTestImageName, "", "", os.Stdout, utils.NewStreamFormatter(false)); err != nil { panic(err) } } diff --git a/components/engine/server.go b/components/engine/server.go index 3303c7c5a1..3353796475 100644 --- a/components/engine/server.go +++ b/components/engine/server.go @@ -67,7 +67,7 @@ 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, sf *utils.StreamFormatter) error { out = utils.NewWriteFlusher(out) img, err := srv.runtime.repositories.LookupImage(name) if err != nil { @@ -91,7 +91,7 @@ func (srv *Server) ImageInsert(name, url, path string, out io.Writer) error { return err } - if err := c.Inject(utils.ProgressReader(file.Body, int(file.ContentLength), out, "Downloading %v/%v (%v)\r", false), path); err != nil { + if err := c.Inject(utils.ProgressReader(file.Body, int(file.ContentLength), out, sf.FormatProgress("Downloading", "%v/%v (%v)"), sf), path); err != nil { return err } // FIXME: Handle custom repo, tag comment, author @@ -99,7 +99,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) + fmt.Fprintf(out, sf.FormatStatus("%s"), img.Id) return nil } @@ -291,7 +291,7 @@ func (srv *Server) ContainerTag(name, repo, tag string, force bool) error { return nil } -func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []string, json bool) error { +func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []string, sf *utils.StreamFormatter) error { history, err := srv.registry.GetRemoteHistory(imgId, registry, token) if err != nil { return err @@ -301,7 +301,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, utils.FormatStatus("Pulling %s metadata", json), id) + fmt.Fprintf(out, sf.FormatStatus("Pulling %s metadata"), id) imgJson, err := srv.registry.GetRemoteImageJson(id, registry, token) if err != nil { // FIXME: Keep goging in case of error? @@ -313,12 +313,12 @@ func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []stri } // Get the layer - fmt.Fprintf(out, utils.FormatStatus("Pulling %s fs layer", json), id) + fmt.Fprintf(out, sf.FormatStatus("Pulling %s fs layer"), 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, utils.FormatProgress("%v/%v (%v)", json), json), false, img); err != nil { + if err := srv.runtime.graph.Register(utils.ProgressReader(layer, contentLength, out, sf.FormatProgress("Downloading", "%v/%v (%v)"), sf), false, img); err != nil { return err } } @@ -326,8 +326,8 @@ func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []stri return nil } -func (srv *Server) pullRepository(out io.Writer, remote, askedTag string, json bool) error { - fmt.Fprintf(out, utils.FormatStatus("Pulling repository %s from %s", json), remote, auth.IndexServerAddress()) +func (srv *Server) pullRepository(out io.Writer, remote, askedTag string, sf *utils.StreamFormatter) error { + fmt.Fprintf(out, sf.FormatStatus("Pulling repository %s from %s"), remote, auth.IndexServerAddress()) repoData, err := srv.registry.GetRepositoryData(remote) if err != nil { return err @@ -364,11 +364,11 @@ func (srv *Server) pullRepository(out io.Writer, remote, askedTag string, json b utils.Debugf("(%s) does not match %s (id: %s), skipping", img.Tag, askedTag, img.Id) continue } - fmt.Fprintf(out, utils.FormatStatus("Pulling image %s (%s) from %s", json), img.Id, img.Tag, remote) + fmt.Fprintf(out, sf.FormatStatus("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, json); err != nil { - fmt.Fprintf(out, utils.FormatStatus("Error while retrieving image for tag: %s (%s); checking next endpoint\n", json), askedTag, err) + if err := srv.pullImage(out, img.Id, "https://"+ep+"/v1", repoData.Tokens, sf); err != nil { + fmt.Fprintf(out, sf.FormatStatus("Error while retrieving image for tag: %s (%s); checking next endpoint\n"), askedTag, err) continue } success = true @@ -393,16 +393,16 @@ func (srv *Server) pullRepository(out io.Writer, remote, askedTag string, json b return nil } -func (srv *Server) ImagePull(name, tag, registry string, out io.Writer, json bool) error { +func (srv *Server) ImagePull(name, tag, registry string, out io.Writer, sf *utils.StreamFormatter) error { out = utils.NewWriteFlusher(out) if registry != "" { - if err := srv.pullImage(out, name, registry, nil, json); err != nil { + if err := srv.pullImage(out, name, registry, nil, sf); err != nil { return err } return nil } - if err := srv.pullRepository(out, name, tag, json); err != nil { + if err := srv.pullRepository(out, name, tag, sf); err != nil { return err } @@ -475,14 +475,14 @@ func (srv *Server) getImageList(localRepo map[string]string) ([]*registry.ImgDat return imgList, nil } -func (srv *Server) pushRepository(out io.Writer, name string, localRepo map[string]string) error { +func (srv *Server) pushRepository(out io.Writer, name string, localRepo map[string]string, sf *utils.StreamFormatter) error { out = utils.NewWriteFlusher(out) - fmt.Fprintf(out, "Processing checksums\n") + fmt.Fprintf(out, sf.FormatStatus("Processing checksums")) imgList, err := srv.getImageList(localRepo) if err != nil { return err } - fmt.Fprintf(out, "Sending image list\n") + fmt.Fprintf(out, sf.FormatStatus("Sending image list")) repoData, err := srv.registry.PushImageJsonIndex(name, imgList, false) if err != nil { @@ -491,18 +491,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)) + fmt.Fprintf(out, sf.FormatStatus("Pushing repository %s to %s (%d tags)"), 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) + fmt.Fprintf(out, sf.FormatStatus("Image %s already on registry, skipping"), name) continue } - if err := srv.pushImage(out, name, elem.Id, ep, repoData.Tokens); err != nil { + if err := srv.pushImage(out, name, elem.Id, ep, repoData.Tokens, sf); 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) + fmt.Fprintf(out, sf.FormatStatus("Pushing tags for rev [%s] on {%s}"), elem.Id, ep+"/users/"+name+"/"+elem.Tag) if err := srv.registry.PushRegistryTag(name, elem.Id, elem.Tag, ep, repoData.Tokens); err != nil { return err } @@ -515,13 +515,13 @@ func (srv *Server) pushRepository(out io.Writer, name string, localRepo map[stri return nil } -func (srv *Server) pushImage(out io.Writer, remote, imgId, ep string, token []string) error { +func (srv *Server) pushImage(out io.Writer, remote, imgId, ep string, token []string, sf *utils.StreamFormatter) error { 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) } - fmt.Fprintf(out, "Pushing %s\r\n", imgId) + fmt.Fprintf(out, sf.FormatStatus("Pushing %s"), imgId) // Make sure we have the image's checksum checksum, err := srv.getChecksum(imgId) @@ -536,7 +536,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) + fmt.Fprintf(out, sf.FormatStatus("Image %s already uploaded ; skipping"), imgData.Id) return nil } return err @@ -569,20 +569,20 @@ func (srv *Server) pushImage(out io.Writer, remote, imgId, ep string, token []st } // Send the layer - if err := srv.registry.PushImageLayerRegistry(imgData.Id, utils.ProgressReader(layerData, int(layerData.Size), out, "", false), ep, token); err != nil { + if err := srv.registry.PushImageLayerRegistry(imgData.Id, utils.ProgressReader(layerData, int(layerData.Size), out, sf.FormatProgress("", "%v/%v (%v)"), sf), ep, token); err != nil { return err } return nil } -func (srv *Server) ImagePush(name, registry string, out io.Writer) error { +func (srv *Server) ImagePush(name, registry string, out io.Writer, sf *utils.StreamFormatter) error { 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])) + fmt.Fprintf(out, sf.FormatStatus("The push refers to a repository [%s] (len: %d)"), 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 { + if err := srv.pushRepository(out, name, localRepo, sf); err != nil { return err } return nil @@ -590,14 +590,14 @@ 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) - if err := srv.pushImage(out, name, img.Id, registry, nil); err != nil { + fmt.Fprintf(out, sf.FormatStatus("The push refers to an image: [%s]"), name) + if err := srv.pushImage(out, name, img.Id, registry, nil, sf); err != nil { return err } return nil } -func (srv *Server) ImageImport(src, repo, tag string, in io.Reader, out io.Writer) error { +func (srv *Server) ImageImport(src, repo, tag string, in io.Reader, out io.Writer, sf *utils.StreamFormatter) error { var archive io.Reader var resp *http.Response @@ -606,21 +606,21 @@ 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) + return err } if u.Scheme == "" { u.Scheme = "http" u.Host = src u.Path = "" } - fmt.Fprintf(out, "Downloading from %s\n", u) + fmt.Fprintf(out, sf.FormatStatus("Downloading from %s"), u) // Download with curl (pretty progress bar) // If curl is not available, fallback to http.Get() resp, err = utils.Download(u.String(), out) if err != nil { return err } - archive = utils.ProgressReader(resp.Body, int(resp.ContentLength), out, "Importing %v/%v (%v)\r", false) + archive = utils.ProgressReader(resp.Body, int(resp.ContentLength), out, sf.FormatProgress("Importing", "%v/%v (%v)"), sf) } img, err := srv.runtime.graph.Create(archive, nil, "Imported from "+src, "", nil) if err != nil { @@ -632,7 +632,7 @@ func (srv *Server) ImageImport(src, repo, tag string, in io.Reader, out io.Write return err } } - fmt.Fprintf(out, "%s\n", img.ShortId()) + fmt.Fprintf(out, sf.FormatStatus(img.ShortId())) return nil } diff --git a/components/engine/utils/utils.go b/components/engine/utils/utils.go index 8588c52478..ec05c657e3 100644 --- a/components/engine/utils/utils.go +++ b/components/engine/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 + sf *StreamFormatter } func (r *progressReader) Read(p []byte) (n int, err error) { @@ -93,7 +93,7 @@ func (r *progressReader) Read(p []byte) (n int, err error) { } // Send newline when complete if err != nil { - fmt.Fprintf(r.output, FormatStatus("", r.json)) + fmt.Fprintf(r.output, r.sf.FormatStatus("")) } return read, err @@ -101,11 +101,11 @@ func (r *progressReader) Read(p []byte) (n int, err error) { 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 { +func ProgressReader(r io.ReadCloser, size int, output io.Writer, template string, sf *StreamFormatter) *progressReader { if template == "" { - template = "%v/%v (%v)\r" + template = "%v/%v (%v)" } - return &progressReader{r, NewWriteFlusher(output), size, 0, 0, template, json} + return &progressReader{r, NewWriteFlusher(output), size, 0, 0, template, sf} } // HumanDuration returns a human-readable approximation of a duration @@ -557,25 +557,41 @@ func NewWriteFlusher(w io.Writer) *WriteFlusher { return &WriteFlusher{w: w, flusher: flusher} } -func FormatStatus(str string, json bool) string { - if json { +type StreamFormatter struct { + json bool + used bool +} + +func NewStreamFormatter(json bool) *StreamFormatter { + return &StreamFormatter{json, false} +} + +func (sf *StreamFormatter) FormatStatus(str string) string { + sf.used = true + if sf.json { return "{\"status\" : \"" + str + "\"}" } return str + "\r\n" } -func FormatError(str string, json bool) string { - if json { - return "{\"error\" : \"" + str + "\"}" +func (sf *StreamFormatter) FormatError(err error) string { + sf.used = true + if sf.json { + return "{\"error\" : \"" + err.Error() + "\"}" } - return "Error: " + str + "\r\n" + return "Error: " + err.Error() + "\r\n" } -func FormatProgress(str string, json bool) string { - if json { +func (sf *StreamFormatter) FormatProgress(action, str string) string { + sf.used = true + if sf.json { return "{\"progress\" : \"" + str + "\"}" } - return "Downloading " + str + "\r" + return action + " " + str + "\r" +} + +func (sf *StreamFormatter) Used() bool { + return sf.used } From b088e2de7051ed3e18e763186947b0504293e4bb Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Sat, 25 May 2013 15:51:26 +0000 Subject: [PATCH 06/61] ensure valid json Upstream-commit: 14212930e40439d0cfc635d56e084736867f9e30 Component: engine --- components/engine/commands.go | 7 +------ components/engine/server.go | 2 +- components/engine/utils/utils.go | 24 +++++++++++++++++++++--- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/components/engine/commands.go b/components/engine/commands.go index 01ab8a334f..7a0a5be3ee 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -1258,14 +1258,9 @@ func (cli *DockerCli) stream(method, path string, in io.Reader, out io.Writer) e } if resp.Header.Get("Content-Type") == "application/json" { - type Message struct { - Status string `json:"status,omitempty"` - Progress string `json:"progress,omitempty"` - Error string `json:"error,omitempty"` - } dec := json.NewDecoder(resp.Body) for { - var m Message + var m utils.JsonMessage if err := dec.Decode(&m); err == io.EOF { break } else if err != nil { diff --git a/components/engine/server.go b/components/engine/server.go index 3353796475..6ebf337dd0 100644 --- a/components/engine/server.go +++ b/components/engine/server.go @@ -368,7 +368,7 @@ func (srv *Server) pullRepository(out io.Writer, remote, askedTag string, sf *ut success := false for _, ep := range repoData.Endpoints { if err := srv.pullImage(out, img.Id, "https://"+ep+"/v1", repoData.Tokens, sf); err != nil { - fmt.Fprintf(out, sf.FormatStatus("Error while retrieving image for tag: %s (%s); checking next endpoint\n"), askedTag, err) + fmt.Fprintf(out, sf.FormatStatus("Error while retrieving image for tag: %s (%s); checking next endpoint"), askedTag, err) continue } success = true diff --git a/components/engine/utils/utils.go b/components/engine/utils/utils.go index ec05c657e3..1fce76e5aa 100644 --- a/components/engine/utils/utils.go +++ b/components/engine/utils/utils.go @@ -4,6 +4,7 @@ import ( "bytes" "crypto/sha256" "encoding/hex" + "encoding/json" "errors" "fmt" "index/suffixarray" @@ -557,6 +558,12 @@ func NewWriteFlusher(w io.Writer) *WriteFlusher { return &WriteFlusher{w: w, flusher: flusher} } +type JsonMessage struct { + Status string `json:"status,omitempty"` + Progress string `json:"progress,omitempty"` + Error string `json:"error,omitempty"` +} + type StreamFormatter struct { json bool used bool @@ -569,7 +576,11 @@ func NewStreamFormatter(json bool) *StreamFormatter { func (sf *StreamFormatter) FormatStatus(str string) string { sf.used = true if sf.json { - return "{\"status\" : \"" + str + "\"}" + b, err := json.Marshal(&JsonMessage{Status:str}); + if err != nil { + return sf.FormatError(err) + } + return string(b) } return str + "\r\n" } @@ -577,7 +588,10 @@ func (sf *StreamFormatter) FormatStatus(str string) string { func (sf *StreamFormatter) FormatError(err error) string { sf.used = true if sf.json { - return "{\"error\" : \"" + err.Error() + "\"}" + if b, err := json.Marshal(&JsonMessage{Error:err.Error()}); err == nil { + return string(b) + } + return "{\"error\":\"format error\"}" } return "Error: " + err.Error() + "\r\n" } @@ -585,7 +599,11 @@ func (sf *StreamFormatter) FormatError(err error) string { func (sf *StreamFormatter) FormatProgress(action, str string) string { sf.used = true if sf.json { - return "{\"progress\" : \"" + str + "\"}" + b, err := json.Marshal(&JsonMessage{Progress:str}) + if err != nil { + return sf.FormatError(err) + } + return string(b) } return action + " " + str + "\r" } From 037b9b61607feac8d063d28726b76b58c428e975 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Sun, 26 May 2013 23:45:45 +0000 Subject: [PATCH 07/61] fix json encoding, and use less casts Upstream-commit: 5a36efb61fae88a7fe71f67a6b1f8b9da6468014 Component: engine --- components/engine/api.go | 8 ++++---- components/engine/graph.go | 3 ++- components/engine/server.go | 34 ++++++++++++++++---------------- components/engine/utils/utils.go | 34 +++++++++++++++++--------------- 4 files changed, 41 insertions(+), 38 deletions(-) diff --git a/components/engine/api.go b/components/engine/api.go index 55fb8d5a66..c5472fa2c2 100644 --- a/components/engine/api.go +++ b/components/engine/api.go @@ -297,7 +297,7 @@ func postImagesCreate(srv *Server, version float64, w http.ResponseWriter, r *ht registry := r.Form.Get("registry") if err := srv.ImagePull(image, tag, registry, w, sf); err != nil { if sf.Used() { - fmt.Fprintf(w, sf.FormatError(err)) + w.Write(sf.FormatError(err)) return nil } return err @@ -305,7 +305,7 @@ func postImagesCreate(srv *Server, version float64, w http.ResponseWriter, r *ht } else { //import if err := srv.ImageImport(src, repo, tag, r.Body, w, sf); err != nil { if sf.Used() { - fmt.Fprintf(w, sf.FormatError(err)) + w.Write(sf.FormatError(err)) return nil } return err @@ -349,7 +349,7 @@ func postImagesInsert(srv *Server, version float64, w http.ResponseWriter, r *ht sf := utils.NewStreamFormatter(version > 1.0) if err := srv.ImageInsert(name, url, path, w, sf); err != nil { if sf.Used() { - fmt.Fprintf(w, sf.FormatError(err)) + w.Write(sf.FormatError(err)) return nil } return err @@ -373,7 +373,7 @@ func postImagesPush(srv *Server, version float64, w http.ResponseWriter, r *http sf := utils.NewStreamFormatter(version > 1.0) if err := srv.ImagePush(name, registry, w, sf); err != nil { if sf.Used() { - fmt.Fprintf(w, sf.FormatError(err)) + w.Write(sf.FormatError(err)) return nil } return err diff --git a/components/engine/graph.go b/components/engine/graph.go index 0090d51636..befb5ace5e 100644 --- a/components/engine/graph.go +++ b/components/engine/graph.go @@ -165,7 +165,8 @@ func (graph *Graph) TempLayerArchive(id string, compression Compression, output if err != nil { return nil, err } - return NewTempArchive(utils.ProgressReader(ioutil.NopCloser(archive), 0, output, "Buffering to disk %v/%v (%v)", utils.NewStreamFormatter(false)), tmp.Root) + sf := utils.NewStreamFormatter(false) + return NewTempArchive(utils.ProgressReader(ioutil.NopCloser(archive), 0, output, sf.FormatProgress("Buffering to disk", "%v/%v (%v)"), sf), tmp.Root) } // Mktemp creates a temporary sub-directory inside the graph's filesystem. diff --git a/components/engine/server.go b/components/engine/server.go index 6ebf337dd0..8799c6dc51 100644 --- a/components/engine/server.go +++ b/components/engine/server.go @@ -99,7 +99,7 @@ func (srv *Server) ImageInsert(name, url, path string, out io.Writer, sf *utils. if err != nil { return err } - fmt.Fprintf(out, sf.FormatStatus("%s"), img.Id) + out.Write(sf.FormatStatus(img.Id)) return nil } @@ -301,7 +301,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, sf.FormatStatus("Pulling %s metadata"), id) + out.Write(sf.FormatStatus("Pulling %s metadata", id)) imgJson, err := srv.registry.GetRemoteImageJson(id, registry, token) if err != nil { // FIXME: Keep goging in case of error? @@ -313,7 +313,7 @@ func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []stri } // Get the layer - fmt.Fprintf(out, sf.FormatStatus("Pulling %s fs layer"), id) + out.Write(sf.FormatStatus("Pulling %s fs layer", id)) layer, contentLength, err := srv.registry.GetRemoteImageLayer(img.Id, registry, token) if err != nil { return err @@ -327,7 +327,7 @@ func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []stri } func (srv *Server) pullRepository(out io.Writer, remote, askedTag string, sf *utils.StreamFormatter) error { - fmt.Fprintf(out, sf.FormatStatus("Pulling repository %s from %s"), remote, auth.IndexServerAddress()) + out.Write(sf.FormatStatus("Pulling repository %s from %s", remote, auth.IndexServerAddress())) repoData, err := srv.registry.GetRepositoryData(remote) if err != nil { return err @@ -364,11 +364,11 @@ func (srv *Server) pullRepository(out io.Writer, remote, askedTag string, sf *ut utils.Debugf("(%s) does not match %s (id: %s), skipping", img.Tag, askedTag, img.Id) continue } - fmt.Fprintf(out, sf.FormatStatus("Pulling image %s (%s) from %s"), img.Id, img.Tag, remote) + out.Write(sf.FormatStatus("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, sf); err != nil { - fmt.Fprintf(out, sf.FormatStatus("Error while retrieving image for tag: %s (%s); checking next endpoint"), askedTag, err) + out.Write(sf.FormatStatus("Error while retrieving image for tag: %s (%s); checking next endpoint", askedTag, err)) continue } success = true @@ -477,12 +477,12 @@ func (srv *Server) getImageList(localRepo map[string]string) ([]*registry.ImgDat func (srv *Server) pushRepository(out io.Writer, name string, localRepo map[string]string, sf *utils.StreamFormatter) error { out = utils.NewWriteFlusher(out) - fmt.Fprintf(out, sf.FormatStatus("Processing checksums")) + out.Write(sf.FormatStatus("Processing checksums")) imgList, err := srv.getImageList(localRepo) if err != nil { return err } - fmt.Fprintf(out, sf.FormatStatus("Sending image list")) + out.Write(sf.FormatStatus("Sending image list")) repoData, err := srv.registry.PushImageJsonIndex(name, imgList, false) if err != nil { @@ -491,18 +491,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, sf.FormatStatus("Pushing repository %s to %s (%d tags)"), name, ep, len(localRepo)) + out.Write(sf.FormatStatus("Pushing repository %s to %s (%d tags)", 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, sf.FormatStatus("Image %s already on registry, skipping"), name) + out.Write(sf.FormatStatus("Image %s already on registry, skipping", name)) continue } if err := srv.pushImage(out, name, elem.Id, ep, repoData.Tokens, sf); err != nil { // FIXME: Continue on error? return err } - fmt.Fprintf(out, sf.FormatStatus("Pushing tags for rev [%s] on {%s}"), elem.Id, ep+"/users/"+name+"/"+elem.Tag) + out.Write(sf.FormatStatus("Pushing tags for rev [%s] on {%s}", elem.Id, ep+"/users/"+name+"/"+elem.Tag)) if err := srv.registry.PushRegistryTag(name, elem.Id, elem.Tag, ep, repoData.Tokens); err != nil { return err } @@ -521,7 +521,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, sf.FormatStatus("Pushing %s"), imgId) + out.Write(sf.FormatStatus("Pushing %s", imgId)) // Make sure we have the image's checksum checksum, err := srv.getChecksum(imgId) @@ -536,7 +536,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, sf.FormatStatus("Image %s already uploaded ; skipping"), imgData.Id) + out.Write(sf.FormatStatus("Image %s already uploaded ; skipping", imgData.Id)) return nil } return err @@ -579,7 +579,7 @@ func (srv *Server) ImagePush(name, registry string, out io.Writer, sf *utils.Str out = utils.NewWriteFlusher(out) img, err := srv.runtime.graph.Get(name) if err != nil { - fmt.Fprintf(out, sf.FormatStatus("The push refers to a repository [%s] (len: %d)"), name, len(srv.runtime.repositories.Repositories[name])) + out.Write(sf.FormatStatus("The push refers to a repository [%s] (len: %d)", 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, sf); err != nil { @@ -590,7 +590,7 @@ func (srv *Server) ImagePush(name, registry string, out io.Writer, sf *utils.Str return err } - fmt.Fprintf(out, sf.FormatStatus("The push refers to an image: [%s]"), name) + out.Write(sf.FormatStatus("The push refers to an image: [%s]", name)) if err := srv.pushImage(out, name, img.Id, registry, nil, sf); err != nil { return err } @@ -613,7 +613,7 @@ func (srv *Server) ImageImport(src, repo, tag string, in io.Reader, out io.Write u.Host = src u.Path = "" } - fmt.Fprintf(out, sf.FormatStatus("Downloading from %s"), u) + out.Write(sf.FormatStatus("Downloading from %s", u)) // Download with curl (pretty progress bar) // If curl is not available, fallback to http.Get() resp, err = utils.Download(u.String(), out) @@ -632,7 +632,7 @@ func (srv *Server) ImageImport(src, repo, tag string, in io.Reader, out io.Write return err } } - fmt.Fprintf(out, sf.FormatStatus(img.ShortId())) + out.Write(sf.FormatStatus(img.ShortId())) return nil } diff --git a/components/engine/utils/utils.go b/components/engine/utils/utils.go index 1fce76e5aa..64aa111717 100644 --- a/components/engine/utils/utils.go +++ b/components/engine/utils/utils.go @@ -94,7 +94,7 @@ func (r *progressReader) Read(p []byte) (n int, err error) { } // Send newline when complete if err != nil { - fmt.Fprintf(r.output, r.sf.FormatStatus("")) + r.output.Write(r.sf.FormatStatus("")) } return read, err @@ -102,11 +102,12 @@ func (r *progressReader) Read(p []byte) (n int, err error) { func (r *progressReader) Close() error { return io.ReadCloser(r.reader).Close() } -func ProgressReader(r io.ReadCloser, size int, output io.Writer, template string, sf *StreamFormatter) *progressReader { - if template == "" { - template = "%v/%v (%v)" +func ProgressReader(r io.ReadCloser, size int, output io.Writer, template []byte, sf *StreamFormatter) *progressReader { + tpl := string(template) + if tpl == "" { + tpl = "%v/%v (%v)" } - return &progressReader{r, NewWriteFlusher(output), size, 0, 0, template, sf} + return &progressReader{r, NewWriteFlusher(output), size, 0, 0, tpl, sf} } // HumanDuration returns a human-readable approximation of a duration @@ -573,39 +574,40 @@ func NewStreamFormatter(json bool) *StreamFormatter { return &StreamFormatter{json, false} } -func (sf *StreamFormatter) FormatStatus(str string) string { +func (sf *StreamFormatter) FormatStatus(format string, a ...interface{}) []byte { sf.used = true + str := fmt.Sprintf(format, a...) if sf.json { b, err := json.Marshal(&JsonMessage{Status:str}); if err != nil { return sf.FormatError(err) } - return string(b) + return b } - return str + "\r\n" + return []byte(str + "\r\n") } -func (sf *StreamFormatter) FormatError(err error) string { +func (sf *StreamFormatter) FormatError(err error) []byte { sf.used = true if sf.json { if b, err := json.Marshal(&JsonMessage{Error:err.Error()}); err == nil { - return string(b) + return b } - return "{\"error\":\"format error\"}" + return []byte("{\"error\":\"format error\"}") } - return "Error: " + err.Error() + "\r\n" + return []byte("Error: " + err.Error() + "\r\n") } -func (sf *StreamFormatter) FormatProgress(action, str string) string { +func (sf *StreamFormatter) FormatProgress(action, str string) []byte { sf.used = true if sf.json { b, err := json.Marshal(&JsonMessage{Progress:str}) if err != nil { - return sf.FormatError(err) + return nil } - return string(b) + return b } - return action + " " + str + "\r" + return []byte(action + " " + str + "\r") } func (sf *StreamFormatter) Used() bool { From 3d5929f43786f613e7d1445b20c4f9e8a7ef1bb7 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Mon, 27 May 2013 16:07:05 +0000 Subject: [PATCH 08/61] remove hijack on the client in logs, and split stdout / stderr Upstream-commit: fbcd8503b3a29bdbb7a52d6433b0ab79877bc4ce Component: engine --- components/engine/commands.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/components/engine/commands.go b/components/engine/commands.go index 6c4dcd14d6..097ece9fce 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -920,12 +920,10 @@ func (cli *DockerCli) CmdLogs(args ...string) error { return nil } - v := url.Values{} - v.Set("logs", "1") - v.Set("stdout", "1") - v.Set("stderr", "1") - - if err := cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), false); err != nil { + if err := cli.stream("POST", "/containers/"+cmd.Arg(0)+"/attach?logs=1&stdout=1", nil, os.Stdout); err != nil { + return err + } + if err := cli.stream("POST", "/containers/"+cmd.Arg(0)+"/attach?logs=1&stderr=1", nil, os.Stderr); err != nil { return err } return nil From 663bde65c37cca82d30db71912512f106ee51a28 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Tue, 28 May 2013 15:49:57 +0000 Subject: [PATCH 09/61] documentation Upstream-commit: 8699805756d25602e2412173aac7364fbe9627c7 Component: engine --- .../docs/sources/api/docker_remote_api.rst | 57 ++++++++++++++++--- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/components/engine/docs/sources/api/docker_remote_api.rst b/components/engine/docs/sources/api/docker_remote_api.rst index 4c8ebe847f..3920aba983 100644 --- a/components/engine/docs/sources/api/docker_remote_api.rst +++ b/components/engine/docs/sources/api/docker_remote_api.rst @@ -15,10 +15,17 @@ Docker Remote API - 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 is hijacked to transport stdout stdin and stderr -2. Endpoints +2. Version +========== + +The current verson of the API is 1.1 +Calling /images//insert is the same as calling /v1.1/images//insert +You can still call an old version of the api using /v1.0/images//insert + +3. Endpoints ============ -2.1 Containers +3.1 Containers -------------- List containers @@ -459,7 +466,7 @@ Remove a container :statuscode 500: server error -2.2 Images +3.2 Images ---------- List Images @@ -548,7 +555,19 @@ Create an image POST /images/create?fromImage=base HTTP/1.1 - **Example response**: + **Example response v1.1**: + + .. sourcecode:: http + + HTTP/1.1 200 OK + Content-Type: application/json + + {"status":"Pulling..."} + {"progress":"1/? (n/a)"} + {"error":"Invalid..."} + ... + + **Example response v1.0**: .. sourcecode:: http @@ -579,7 +598,19 @@ Insert a file in a image POST /images/test/insert?path=/usr&url=myurl HTTP/1.1 - **Example response**: + **Example response v1.1**: + + .. sourcecode:: http + + HTTP/1.1 200 OK + Content-Type: application/json + + {"status":"Inserting..."} + {"progress":"1/? (n/a)"} + {"error":"Invalid..."} + ... + + **Example response v1.0**: .. sourcecode:: http @@ -694,7 +725,19 @@ Push an image on the registry POST /images/test/push HTTP/1.1 - **Example response**: + **Example response v1.1**: + + .. sourcecode:: http + + HTTP/1.1 200 OK + Content-Type: application/json + + {"status":"Pushing..."} + {"progress":"1/? (n/a)"} + {"error":"Invalid..."} + ... + + **Example response v1.0**: .. sourcecode:: http @@ -800,7 +843,7 @@ Search images :statuscode 500: server error -2.3 Misc +3.3 Misc -------- Build an image from Dockerfile via stdin From 581102927da152b114359c938ae7e75f730c85ec Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 29 May 2013 11:40:54 +0000 Subject: [PATCH 10/61] improve attach Upstream-commit: c00d1a6ebe8dd607b1876e505e1761c2a548aa53 Component: engine --- components/engine/commands.go | 93 ++++++++++++++++++++++++----------- 1 file changed, 65 insertions(+), 28 deletions(-) diff --git a/components/engine/commands.go b/components/engine/commands.go index 6c4dcd14d6..09595e9c38 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -925,7 +925,7 @@ func (cli *DockerCli) CmdLogs(args ...string) error { v.Set("stdout", "1") v.Set("stderr", "1") - if err := cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), false); err != nil { + if err := cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), false, nil, os.Stdout); err != nil { return err } return nil @@ -951,16 +951,33 @@ func (cli *DockerCli) CmdAttach(args ...string) error { if err != nil { return err } - + connections := 1 + if !container.Config.Tty { + connections += 1 + } + c := make(chan error, 2) + cli.monitorTtySize(cmd.Arg(0)) + if !container.Config.Tty { + go func() { + c <- cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?stream=1&stderr=1", false, nil, os.Stderr) + }() + } v := url.Values{} v.Set("stream", "1") - v.Set("stdout", "1") - 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 + v.Set("stdout", "1") + if container.Config.Tty { + v.Set("stderr", "1") + } + go func() { + c <- cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), container.Config.Tty, os.Stdin, os.Stdout) + }() + for connections > 0 { + err := <-c + if err != nil { + return err + } + connections -= 1 } return nil } @@ -1124,19 +1141,12 @@ func (cli *DockerCli) CmdRun(args ...string) error { fmt.Fprintln(os.Stderr, "WARNING: ", warning) } - v := url.Values{} - v.Set("logs", "1") - v.Set("stream", "1") - - if config.AttachStdin { - v.Set("stdin", "1") + connections := 0 + if config.AttachStdin || config.AttachStdout { + connections += 1 } - if config.AttachStdout { - v.Set("stdout", "1") - } - if config.AttachStderr { - v.Set("stderr", "1") - + if !config.Tty && config.AttachStderr { + connections += 1 } //start the container @@ -1145,10 +1155,38 @@ func (cli *DockerCli) CmdRun(args ...string) error { return err } - if config.AttachStdin || config.AttachStdout || config.AttachStderr { + if connections > 0 { + c := make(chan error, connections) cli.monitorTtySize(out.Id) - if err := cli.hijack("POST", "/containers/"+out.Id+"/attach?"+v.Encode(), config.Tty); err != nil { - return err + + if !config.Tty && config.AttachStderr { + go func() { + c <- cli.hijack("POST", "/containers/"+out.Id+"/attach?logs=1&stream=1&stderr=1", config.Tty, nil, os.Stderr) + }() + } + + v := url.Values{} + v.Set("logs", "1") + v.Set("stream", "1") + + if config.AttachStdin { + v.Set("stdin", "1") + } + if config.AttachStdout { + v.Set("stdout", "1") + } + if config.Tty && config.AttachStderr { + v.Set("stderr", "1") + } + go func() { + c <- cli.hijack("POST", "/containers/"+out.Id+"/attach?"+v.Encode(), config.Tty, os.Stdin, os.Stdout) + }() + for connections > 0 { + err := <-c + if err != nil { + return err + } + connections -= 1 } } if !config.AttachStdout && !config.AttachStderr { @@ -1284,7 +1322,7 @@ func (cli *DockerCli) stream(method, path string, in io.Reader, out io.Writer) e return nil } -func (cli *DockerCli) hijack(method, path string, setRawTerminal bool) error { +func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in *os.File, out io.Writer) error { req, err := http.NewRequest(method, fmt.Sprintf("/v%g%s", API_VERSION, path), nil) if err != nil { return err @@ -1302,20 +1340,19 @@ func (cli *DockerCli) hijack(method, path string, setRawTerminal bool) error { defer rwc.Close() receiveStdout := utils.Go(func() error { - _, err := io.Copy(os.Stdout, br) + _, err := io.Copy(out, br) return err }) - if setRawTerminal && term.IsTerminal(int(os.Stdin.Fd())) && os.Getenv("NORAW") == "" { + if in != nil && setRawTerminal && term.IsTerminal(int(in.Fd())) && os.Getenv("NORAW") == "" { if oldState, err := term.SetRawTerminal(); err != nil { return err } else { defer term.RestoreTerminal(oldState) } } - sendStdin := utils.Go(func() error { - _, err := io.Copy(rwc, os.Stdin) + _, err := io.Copy(rwc, in) if err := rwc.(*net.TCPConn).CloseWrite(); err != nil { fmt.Fprintf(os.Stderr, "Couldn't send EOF: %s\n", err) } From 753326bb69e030992491d02f977307771def5b4a Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 29 May 2013 14:14:51 +0000 Subject: [PATCH 11/61] split stdout and stderr in run if not -t Upstream-commit: e33ba9b36daa5e72e33d65b316059cddc756e0e9 Component: engine --- components/engine/commands.go | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/components/engine/commands.go b/components/engine/commands.go index 899b847ae9..38a30610f7 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -1016,29 +1016,32 @@ func (cli *DockerCli) CmdAttach(args ...string) error { if err != nil { return err } + + splitStderr := container.Config.Tty + connections := 1 - if !container.Config.Tty { + if splitStderr { connections += 1 } - c := make(chan error, 2) + chErrors := make(chan error, connections) cli.monitorTtySize(cmd.Arg(0)) - if !container.Config.Tty { + if splitStderr { go func() { - c <- cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?stream=1&stderr=1", false, nil, os.Stderr) + chErrors <- cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?stream=1&stderr=1", false, nil, os.Stderr) }() } v := url.Values{} v.Set("stream", "1") v.Set("stdin", "1") v.Set("stdout", "1") - if container.Config.Tty { + if !splitStderr { v.Set("stderr", "1") } go func() { - c <- cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), container.Config.Tty, os.Stdin, os.Stdout) + chErrors <- cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), container.Config.Tty, os.Stdin, os.Stdout) }() for connections > 0 { - err := <-c + err := <-chErrors if err != nil { return err } @@ -1206,11 +1209,13 @@ func (cli *DockerCli) CmdRun(args ...string) error { fmt.Fprintln(os.Stderr, "WARNING: ", warning) } + splitStderr := !config.Tty + connections := 0 - if config.AttachStdin || config.AttachStdout { + if config.AttachStdin || config.AttachStdout || (!splitStderr && config.AttachStderr) { connections += 1 } - if !config.Tty && config.AttachStderr { + if splitStderr && config.AttachStderr { connections += 1 } @@ -1221,12 +1226,12 @@ func (cli *DockerCli) CmdRun(args ...string) error { } if connections > 0 { - c := make(chan error, connections) + chErrors := make(chan error, connections) cli.monitorTtySize(out.Id) - if !config.Tty && config.AttachStderr { + if splitStderr && config.AttachStderr { go func() { - c <- cli.hijack("POST", "/containers/"+out.Id+"/attach?logs=1&stream=1&stderr=1", config.Tty, nil, os.Stderr) + chErrors <- cli.hijack("POST", "/containers/"+out.Id+"/attach?logs=1&stream=1&stderr=1", config.Tty, nil, os.Stderr) }() } @@ -1240,14 +1245,14 @@ func (cli *DockerCli) CmdRun(args ...string) error { if config.AttachStdout { v.Set("stdout", "1") } - if config.Tty && config.AttachStderr { + if !splitStderr && config.AttachStderr { v.Set("stderr", "1") } go func() { - c <- cli.hijack("POST", "/containers/"+out.Id+"/attach?"+v.Encode(), config.Tty, os.Stdin, os.Stdout) + chErrors <- cli.hijack("POST", "/containers/"+out.Id+"/attach?"+v.Encode(), config.Tty, os.Stdin, os.Stdout) }() for connections > 0 { - err := <-c + err := <-chErrors if err != nil { return err } From a2aa645fe36b731b09399a1786308416b9e609ab Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Wed, 29 May 2013 10:51:47 -0700 Subject: [PATCH 12/61] Update docker build UI Upstream-commit: 75d2244023cd39af17976c56225da6b5158ff68f Component: engine --- components/engine/commands.go | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/components/engine/commands.go b/components/engine/commands.go index e34c40f8cc..501dea6043 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -17,6 +17,7 @@ import ( "net/url" "os" "os/signal" + "path" "path/filepath" "reflect" "strconv" @@ -130,17 +131,12 @@ func (cli *DockerCli) CmdInsert(args ...string) error { } func (cli *DockerCli) CmdBuild(args ...string) error { - cmd := Subcmd("build", "[OPTIONS] [CONTEXT]", "Build an image from a Dockerfile") - fileName := cmd.String("f", "Dockerfile", "Use `file` as Dockerfile. Can be '-' for stdin") + cmd := Subcmd("build", "[CONTEXT]", "Build an image from a Dockerfile") if err := cmd.Parse(args); err != nil { return nil } - var ( - file io.ReadCloser - multipartBody io.Reader - err error - ) + var multipartBody io.Reader // Init the needed component for the Multipart buff := bytes.NewBuffer([]byte{}) @@ -148,17 +144,19 @@ func (cli *DockerCli) CmdBuild(args ...string) error { w := multipart.NewWriter(buff) boundary := strings.NewReader("\r\n--" + w.Boundary() + "--\r\n") - // 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() + dockerfile := "Dockerfile" + + if cmd.Arg(0) != "" { + dockerfile = path.Join(cmd.Arg(0), dockerfile) } - if wField, err := w.CreateFormFile("Dockerfile", *fileName); err != nil { + + // Create a FormFile multipart for the Dockerfile + file, err := os.Open(dockerfile) + if err != nil { + return err + } + defer file.Close() + if wField, err := w.CreateFormFile("Dockerfile", "Dockerfile"); err != nil { return err } else { io.Copy(wField, file) From 71357b495fb5f19ed37b5e0cf7a8515a9b743762 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Wed, 29 May 2013 10:53:24 -0700 Subject: [PATCH 13/61] Fix issue with unknown instruction within docker build Upstream-commit: 6cbc7757b2b4d068a98287754da552028fd62212 Component: engine --- components/engine/buildfile.go | 1 + 1 file changed, 1 insertion(+) diff --git a/components/engine/buildfile.go b/components/engine/buildfile.go index 23f2f47172..b9ca5696d5 100644 --- a/components/engine/buildfile.go +++ b/components/engine/buildfile.go @@ -337,6 +337,7 @@ func (b *buildFile) Build(dockerfile, context io.Reader) (string, error) { 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)) + continue } ret := method.Func.Call([]reflect.Value{reflect.ValueOf(b), reflect.ValueOf(arguments)})[0].Interface() if ret != nil { From 613b6a4f42a89eb55a47e5a4533aa8f48aaba6d7 Mon Sep 17 00:00:00 2001 From: Roberto Gandolfo Hashioka Date: Wed, 29 May 2013 11:29:30 -0700 Subject: [PATCH 14/61] updated the running ssh service example with the video's transcription Upstream-commit: c7af917d13c34c6a008df60fa45079fab32cea70 Component: engine --- .../sources/examples/running_ssh_service.rst | 49 ++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/components/engine/docs/sources/examples/running_ssh_service.rst b/components/engine/docs/sources/examples/running_ssh_service.rst index f418b45266..b262266dec 100644 --- a/components/engine/docs/sources/examples/running_ssh_service.rst +++ b/components/engine/docs/sources/examples/running_ssh_service.rst @@ -20,8 +20,7 @@ minutes and not entirely smooth, but gives you a good idea.
- - + You can also get this sshd container by using :: @@ -30,3 +29,49 @@ You can also get this sshd container by using The password is 'screencast' +**Video's Transcription:** + +.. code-block:: bash + + # Hello! We are going to try and install openssh on a container and run it as a servic + # let's pull base to get a base ubuntu image. + $ docker pull base + # I had it so it was quick + # now let's connect using -i for interactive and with -t for terminal + # we execute /bin/bash to get a prompt. + $ docker run -i -t base /bin/bash + # now let's commit it + # which container was it? + $ docker ps -a |more + $ docker commit a30a3a2f2b130749995f5902f079dc6ad31ea0621fac595128ec59c6da07feea dhrp/sshd + # I gave the name dhrp/sshd for the container + # now we can run it again + $ docker run -d dhrp/sshd /usr/sbin/sshd -D # D for daemon mode + # is it running? + $ docker ps + # yes! + # let's stop it + $ docker stop 0ebf7cec294755399d063f4b1627980d4cbff7d999f0bc82b59c300f8536a562 + $ docker ps + # and reconnect, but now open a port to it + $ docker run -d -p 22 dhrp/sshd /usr/sbin/sshd -D + $ docker port b2b407cf22cf8e7fa3736fa8852713571074536b1d31def3fdfcd9fa4fd8c8c5 22 + # it has now given us a port to connect to + # we have to connect using a public ip of our host + $ hostname + $ ifconfig + $ ssh root@192.168.33.10 -p 49153 + # Ah! forgot to set root passwd + $ docker commit b2b407cf22cf8e7fa3736fa8852713571074536b1d31def3fdfcd9fa4fd8c8c5 dhrp/sshd + $ docker ps -a + $ docker run -i -t dhrp/sshd /bin/bash + $ passwd + $ exit + $ docker commit 9e863f0ca0af31c8b951048ba87641d67c382d08d655c2e4879c51410e0fedc1 dhrp/sshd + $ docker run -d -p 22 dhrp/sshd /usr/sbin/sshd -D + $ docker port a0aaa9558c90cf5c7782648df904a82365ebacce523e4acc085ac1213bfe2206 22 + $ ifconfig + $ ssh root@192.168.33.10 -p 49154 + # Thanks for watching, Thatcher thatcher@dotcloud.com + + From eec17f5c7b2841535d5ba8f17899c53717d776e8 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Wed, 29 May 2013 11:43:29 -0700 Subject: [PATCH 15/61] Allow docker build from stdin Upstream-commit: 33ea1483d5b89559e1fe9a9556e3ea757f673e16 Component: engine --- components/engine/commands.go | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/components/engine/commands.go b/components/engine/commands.go index 501dea6043..8e8e17df81 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -131,12 +131,16 @@ func (cli *DockerCli) CmdInsert(args ...string) error { } func (cli *DockerCli) CmdBuild(args ...string) error { - cmd := Subcmd("build", "[CONTEXT]", "Build an image from a Dockerfile") + cmd := Subcmd("build", "[CONTEXT|-]", "Build an image from a Dockerfile") if err := cmd.Parse(args); err != nil { return nil } - var multipartBody io.Reader + var ( + multipartBody io.Reader + file io.ReadCloser + contextPath string + ) // Init the needed component for the Multipart buff := bytes.NewBuffer([]byte{}) @@ -146,16 +150,23 @@ func (cli *DockerCli) CmdBuild(args ...string) error { dockerfile := "Dockerfile" - if cmd.Arg(0) != "" { + if cmd.Arg(0) != "" && cmd.Arg(0) != "-" { + contextPath = cmd.Arg(0) dockerfile = path.Join(cmd.Arg(0), dockerfile) } + if cmd.Arg(0) != "-" { + f, err := os.Open(dockerfile) + if err != nil { + return err + } + defer f.Close() + file = f + } else { + contextPath = cmd.Arg(1) + file = os.Stdin + } // Create a FormFile multipart for the Dockerfile - file, err := os.Open(dockerfile) - if err != nil { - return err - } - defer file.Close() if wField, err := w.CreateFormFile("Dockerfile", "Dockerfile"); err != nil { return err } else { @@ -166,14 +177,14 @@ func (cli *DockerCli) CmdBuild(args ...string) error { compression := Bzip2 // Create a FormFile multipart for the context if needed - if cmd.Arg(0) != "" { + if contextPath != "" { // FIXME: Use NewTempArchive in order to have the size and avoid too much memory usage? - context, err := Tar(cmd.Arg(0), compression) + context, err := Tar(contextPath, compression) if err != nil { return err } // NOTE: Do this in case '.' or '..' is input - absPath, err := filepath.Abs(cmd.Arg(0)) + absPath, err := filepath.Abs(contextPath) if err != nil { return err } @@ -193,7 +204,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error { return err } req.Header.Set("Content-Type", w.FormDataContentType()) - if cmd.Arg(0) != "" { + if contextPath != "" { req.Header.Set("X-Docker-Context-Compression", compression.Flag()) fmt.Println("Uploading Context...") } From cbcfc9c00c9d8374c7abbb5a56908ac0fc73f9ea Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Wed, 29 May 2013 11:50:49 -0700 Subject: [PATCH 16/61] Update docker build docs Upstream-commit: d97fff60a9275324290bb01b921c9b6b0967a4fd Component: engine --- .../sources/commandline/command/build.rst | 32 +++++++++++++++++-- .../engine/docs/sources/use/builder.rst | 10 ++++-- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/components/engine/docs/sources/commandline/command/build.rst b/components/engine/docs/sources/commandline/command/build.rst index a8d2093a5b..0cb6463e4c 100644 --- a/components/engine/docs/sources/commandline/command/build.rst +++ b/components/engine/docs/sources/commandline/command/build.rst @@ -8,6 +8,32 @@ :: - Usage: docker build - - Example: cat Dockerfile | docker build - - Build a new image from the Dockerfile passed via stdin + Usage: docker build [CONTEXT|-] + Build a new image from a Dockerfile + +Examples +-------- + +.. code-block:: bash + + docker build + +This will take the local Dockerfile without context + +.. code-block:: bash + + docker build - + +This will read a Dockerfile form Stdin without context + +.. code-block:: bash + + docker build . + +This will take the local Dockerfile and set the current directory as context + +.. code-block:: bash + + docker build - . + +This will read a Dockerfile from Stdin and set the current directory as context diff --git a/components/engine/docs/sources/use/builder.rst b/components/engine/docs/sources/use/builder.rst index 4e53ed4a79..abd5b9ecb1 100644 --- a/components/engine/docs/sources/use/builder.rst +++ b/components/engine/docs/sources/use/builder.rst @@ -125,8 +125,14 @@ curl was installed within the image. .. note:: The path must include the file name. -.. note:: - This instruction has temporarily disabled +2.8 ADD +------- + + ``ADD `` + +The `ADD` instruction will insert the files from the `` path of the context into `` path +of the container. +The context must be set in order to use this instruction. (see examples) 3. Dockerfile Examples ====================== From 41337f44f26f245c1a03491c76a5ed360d657006 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Wed, 29 May 2013 11:53:44 -0700 Subject: [PATCH 17/61] Update build doc Upstream-commit: 92939569ab06d13cd179d6e998ef9576d3921bb6 Component: engine --- .../engine/docs/sources/commandline/command/build.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/engine/docs/sources/commandline/command/build.rst b/components/engine/docs/sources/commandline/command/build.rst index 0cb6463e4c..f7df8cbbc3 100644 --- a/components/engine/docs/sources/commandline/command/build.rst +++ b/components/engine/docs/sources/commandline/command/build.rst @@ -2,9 +2,9 @@ :description: Build a new image from the Dockerfile passed via stdin :keywords: build, docker, container, documentation -======================================================== -``build`` -- Build a container from Dockerfile via stdin -======================================================== +================================================ +``build`` -- Build a container from a Dockerfile +================================================ :: From 6cbd6d934f3b28ae76e83e5c8b79efa0b8a1befe Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Wed, 29 May 2013 14:37:03 -0700 Subject: [PATCH 18/61] Fix autorun issue within docker build Upstream-commit: ae0d555022411025607acce43ea1929bafd7174a Component: engine --- components/engine/buildfile.go | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/components/engine/buildfile.go b/components/engine/buildfile.go index b9ca5696d5..0dd9bc049c 100644 --- a/components/engine/buildfile.go +++ b/components/engine/buildfile.go @@ -95,10 +95,12 @@ func (b *buildFile) CmdRun(args string) error { return err } - cmd, env := b.config.Cmd, b.config.Env + cmd := b.config.Cmd b.config.Cmd = nil MergeConfig(b.config, config) + utils.Debugf("Commang to be executed: %v", b.config.Cmd) + if cache, err := b.srv.ImageGetCached(b.image, config); err != nil { return err } else if cache != nil { @@ -111,8 +113,11 @@ func (b *buildFile) CmdRun(args string) error { if err != nil { return err } - b.config.Cmd, b.config.Env = cmd, env - return b.commit(cid) + if err := b.commit(cid, cmd); err != nil { + return err + } + b.config.Cmd = cmd + return nil } func (b *buildFile) CmdEnv(args string) error { @@ -153,6 +158,7 @@ func (b *buildFile) CmdExpose(args string) error { } func (b *buildFile) CmdInsert(args string) error { + if b.image == "" { return fmt.Errorf("Please provide a source image with `from` prior to insert") } @@ -169,6 +175,7 @@ func (b *buildFile) CmdInsert(args string) error { } defer file.Body.Close() + cmd := b.config.Cmd b.config.Cmd = []string{"echo", "INSERT", sourceUrl, "in", destPath} cid, err := b.run() if err != nil { @@ -184,7 +191,7 @@ func (b *buildFile) CmdInsert(args string) error { return err } - return b.commit(cid) + return b.commit(cid, cmd) } func (b *buildFile) CmdAdd(args string) error { @@ -198,6 +205,7 @@ func (b *buildFile) CmdAdd(args string) error { orig := strings.Trim(tmp[0], " ") dest := strings.Trim(tmp[1], " ") + cmd := b.config.Cmd b.config.Cmd = []string{"echo", "PUSH", orig, "in", dest} cid, err := b.run() if err != nil { @@ -236,7 +244,7 @@ func (b *buildFile) CmdAdd(args string) error { } } - return b.commit(cid) + return b.commit(cid, cmd) } func (b *buildFile) run() (string, error) { @@ -265,7 +273,8 @@ func (b *buildFile) run() (string, error) { return c.Id, nil } -func (b *buildFile) commit(id string) error { +// Commit the container with the autorun command +func (b *buildFile) commit(id string, autoCmd []string) error { if b.image == "" { return fmt.Errorf("Please provide a source image with `from` prior to commit") } @@ -286,8 +295,11 @@ func (b *buildFile) commit(id string) error { return fmt.Errorf("An error occured while creating the container") } + // Note: Actually copy the struct + autoConfig := *b.config + autoConfig.Cmd = autoCmd // Commit the container - image, err := b.builder.Commit(container, "", "", "", b.maintainer, nil) + image, err := b.builder.Commit(container, "", "", "", b.maintainer, &autoConfig) if err != nil { return err } @@ -347,7 +359,7 @@ func (b *buildFile) Build(dockerfile, context io.Reader) (string, error) { fmt.Fprintf(b.out, "===> %v\n", b.image) } if b.needCommit { - if err := b.commit(""); err != nil { + if err := b.commit("", nil); err != nil { return "", err } } From b5f45b53d38617759a312e0c1879226131bdf975 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Wed, 29 May 2013 15:03:00 -0700 Subject: [PATCH 19/61] Create a layer for each operation (expose, cmd, etc) Upstream-commit: b6165daa775bbf20451ecbe570ab0fb85ad35128 Component: engine --- components/engine/buildfile.go | 42 ++++++++++------------------------ 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/components/engine/buildfile.go b/components/engine/buildfile.go index 0dd9bc049c..05dafe53e1 100644 --- a/components/engine/buildfile.go +++ b/components/engine/buildfile.go @@ -32,8 +32,6 @@ type buildFile struct { tmpContainers map[string]struct{} tmpImages map[string]struct{} - needCommit bool - out io.Writer } @@ -81,9 +79,8 @@ func (b *buildFile) CmdFrom(name string) error { } func (b *buildFile) CmdMaintainer(name string) error { - b.needCommit = true b.maintainer = name - return nil + return b.commit("", b.config.Cmd, fmt.Sprintf("MAINTAINER %s", name)) } func (b *buildFile) CmdRun(args string) error { @@ -113,7 +110,7 @@ func (b *buildFile) CmdRun(args string) error { if err != nil { return err } - if err := b.commit(cid, cmd); err != nil { + if err := b.commit(cid, cmd, "run"); err != nil { return err } b.config.Cmd = cmd @@ -121,7 +118,6 @@ func (b *buildFile) CmdRun(args string) error { } 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") @@ -136,29 +132,25 @@ func (b *buildFile) CmdEnv(args string) error { } } b.config.Env = append(b.config.Env, key+"="+value) - return nil + return b.commit("", b.config.Cmd, fmt.Sprintf("ENV %s=%s", key, value)) } 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 + cmd = []string{"/bin/sh", "-c", args} } - return nil + return b.commit("", cmd, fmt.Sprintf("CMD %v", cmd)) } func (b *buildFile) CmdExpose(args string) error { ports := strings.Split(args, " ") b.config.PortSpecs = append(ports, b.config.PortSpecs...) - return nil + return b.commit("", b.config.Cmd, fmt.Sprintf("EXPOSE %v", ports)) } func (b *buildFile) CmdInsert(args string) error { - if b.image == "" { return fmt.Errorf("Please provide a source image with `from` prior to insert") } @@ -176,7 +168,7 @@ func (b *buildFile) CmdInsert(args string) error { defer file.Body.Close() cmd := b.config.Cmd - b.config.Cmd = []string{"echo", "INSERT", sourceUrl, "in", destPath} + b.config.Cmd = []string{"/bin/sh", "-c", fmt.Sprintf("#(nop) INSERT %s in %s", sourceUrl, destPath)} cid, err := b.run() if err != nil { return err @@ -190,8 +182,7 @@ func (b *buildFile) CmdInsert(args string) error { if err := container.Inject(file.Body, destPath); err != nil { return err } - - return b.commit(cid, cmd) + return b.commit(cid, cmd, fmt.Sprintf("INSERT %s in %s", sourceUrl, destPath)) } func (b *buildFile) CmdAdd(args string) error { @@ -206,7 +197,7 @@ func (b *buildFile) CmdAdd(args string) error { dest := strings.Trim(tmp[1], " ") cmd := b.config.Cmd - b.config.Cmd = []string{"echo", "PUSH", orig, "in", dest} + b.config.Cmd = []string{"/bin/sh", "-c", fmt.Sprintf("#(nop) ADD %s in %s", orig, dest)} cid, err := b.run() if err != nil { return err @@ -243,8 +234,7 @@ func (b *buildFile) CmdAdd(args string) error { return err } } - - return b.commit(cid, cmd) + return b.commit(cid, cmd, fmt.Sprintf("ADD %s in %s", orig, dest)) } func (b *buildFile) run() (string, error) { @@ -274,20 +264,18 @@ func (b *buildFile) run() (string, error) { } // Commit the container with the autorun command -func (b *buildFile) commit(id string, autoCmd []string) error { +func (b *buildFile) commit(id string, autoCmd []string, comment 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"} + b.config.Cmd = []string{"/bin/sh", "-c", "#(nop) " + comment} if cid, err := b.run(); err != nil { return err } else { id = cid } - b.config.Cmd = cmd } container := b.runtime.Get(id) @@ -305,7 +293,6 @@ func (b *buildFile) commit(id string, autoCmd []string) error { } b.tmpImages[image.Id] = struct{}{} b.image = image.Id - b.needCommit = false return nil } @@ -358,11 +345,6 @@ func (b *buildFile) Build(dockerfile, context io.Reader) (string, error) { fmt.Fprintf(b.out, "===> %v\n", b.image) } - if b.needCommit { - if err := b.commit("", nil); err != nil { - return "", err - } - } if b.image != "" { // The build is successful, keep the temporary containers and images for i := range b.tmpImages { From e52d45783c72034c8bbf981fa3f83ff5c8628e56 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Wed, 29 May 2013 16:10:11 -0700 Subject: [PATCH 20/61] Fix cache miss issue within docker build Upstream-commit: 560a74af1562de007ba487e102fd00a2f658e6a0 Component: engine --- components/engine/buildfile.go | 23 ++++++++++++++++++++--- components/engine/server.go | 19 ++----------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/components/engine/buildfile.go b/components/engine/buildfile.go index 05dafe53e1..60a975c8de 100644 --- a/components/engine/buildfile.go +++ b/components/engine/buildfile.go @@ -98,12 +98,14 @@ func (b *buildFile) CmdRun(args string) error { utils.Debugf("Commang to be executed: %v", b.config.Cmd) - if cache, err := b.srv.ImageGetCached(b.image, config); err != nil { + if cache, err := b.srv.ImageGetCached(b.image, b.config); err != nil { return err } else if cache != nil { - utils.Debugf("Use cached version") + utils.Debugf("[BUILDER] Use cached version") b.image = cache.Id return nil + } else { + utils.Debugf("[BUILDER] Cache miss") } cid, err := b.run() @@ -182,7 +184,11 @@ func (b *buildFile) CmdInsert(args string) error { if err := container.Inject(file.Body, destPath); err != nil { return err } - return b.commit(cid, cmd, fmt.Sprintf("INSERT %s in %s", sourceUrl, destPath)) + if err := b.commit(cid, cmd, fmt.Sprintf("INSERT %s in %s", sourceUrl, destPath)); err != nil { + return err + } + b.config.Cmd = cmd + return nil } func (b *buildFile) CmdAdd(args string) error { @@ -271,6 +277,17 @@ func (b *buildFile) commit(id string, autoCmd []string, comment string) error { b.config.Image = b.image if id == "" { b.config.Cmd = []string{"/bin/sh", "-c", "#(nop) " + comment} + + if cache, err := b.srv.ImageGetCached(b.image, b.config); err != nil { + return err + } else if cache != nil { + utils.Debugf("[BUILDER] Use cached version") + b.image = cache.Id + return nil + } else { + utils.Debugf("[BUILDER] Cache miss") + } + if cid, err := b.run(); err != nil { return err } else { diff --git a/components/engine/server.go b/components/engine/server.go index 0440b0a8a4..0125d2f0c1 100644 --- a/components/engine/server.go +++ b/components/engine/server.go @@ -720,28 +720,13 @@ func (srv *Server) ImageDelete(name string) error { } func (srv *Server) ImageGetCached(imgId string, config *Config) (*Image, error) { - - // Retrieve all images - images, err := srv.runtime.graph.All() + byParent, err := srv.runtime.graph.ByParent() 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 - } + for _, img := range byParent[imgId] { if CompareConfig(&img.ContainerConfig, config) { return img, nil } From e4821e2de7d25e135d970af7823070239e212452 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Wed, 29 May 2013 17:04:46 -0700 Subject: [PATCH 21/61] Remove cache opti that cause wrong cache miss Upstream-commit: 881fdc59edf39ba8d87b44b05db7fcd95661d083 Component: engine --- components/engine/server.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/components/engine/server.go b/components/engine/server.go index 0125d2f0c1..0440b0a8a4 100644 --- a/components/engine/server.go +++ b/components/engine/server.go @@ -720,13 +720,28 @@ func (srv *Server) ImageDelete(name string) error { } func (srv *Server) ImageGetCached(imgId string, config *Config) (*Image, error) { - byParent, err := srv.runtime.graph.ByParent() + + // 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 _, img := range byParent[imgId] { + 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 } From b335672d16f8724367917b46556af8ea1f59b298 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Wed, 29 May 2013 17:58:05 -0700 Subject: [PATCH 22/61] Fix ADD behavior on single files Upstream-commit: faafbf211899bc28e7e21e76de051d87ef5b5cd2 Component: engine --- components/engine/buildfile.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/components/engine/buildfile.go b/components/engine/buildfile.go index 60a975c8de..fa19ab2392 100644 --- a/components/engine/buildfile.go +++ b/components/engine/buildfile.go @@ -213,13 +213,17 @@ func (b *buildFile) CmdAdd(args string) error { if container == nil { return fmt.Errorf("Error while creating the container (CmdAdd)") } - - if err := os.MkdirAll(path.Join(container.rwPath(), dest), 0700); err != nil { + if err := container.EnsureMounted(); err != nil { return err } + defer container.Unmount() origPath := path.Join(b.context, orig) - destPath := path.Join(container.rwPath(), dest) + destPath := path.Join(container.RootfsPath(), dest) + + if err := os.MkdirAll(path.Dir(destPath), 0700); err != nil { + return err + } fi, err := os.Stat(origPath) if err != nil { From 74b27108da1b34bc179177014f0c3a3838276962 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Wed, 29 May 2013 18:14:50 -0700 Subject: [PATCH 23/61] Fixed phrasing, typos and formatting in 'docker build' Upstream-commit: dcab408f6a047d5a4ccac0d3999d8c896f0a63dc Component: engine --- components/engine/buildfile.go | 6 +++--- components/engine/commands.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/engine/buildfile.go b/components/engine/buildfile.go index fa19ab2392..805ebb4fbb 100644 --- a/components/engine/buildfile.go +++ b/components/engine/buildfile.go @@ -96,7 +96,7 @@ func (b *buildFile) CmdRun(args string) error { b.config.Cmd = nil MergeConfig(b.config, config) - utils.Debugf("Commang to be executed: %v", b.config.Cmd) + utils.Debugf("Command to be executed: %v", b.config.Cmd) if cache, err := b.srv.ImageGetCached(b.image, b.config); err != nil { return err @@ -197,7 +197,7 @@ func (b *buildFile) CmdAdd(args string) error { } tmp := strings.SplitN(args, " ", 2) if len(tmp) != 2 { - return fmt.Errorf("Invalid INSERT format") + return fmt.Errorf("Invalid ADD format") } orig := strings.Trim(tmp[0], " ") dest := strings.Trim(tmp[1], " ") @@ -371,7 +371,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 success.\n Image id:\n%s\n", b.image) + fmt.Fprintf(b.out, "Build successful.\n===> %s\n", b.image) return b.image, nil } for i := range b.tmpContainers { diff --git a/components/engine/commands.go b/components/engine/commands.go index 8e8e17df81..6cca487851 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -131,7 +131,7 @@ func (cli *DockerCli) CmdInsert(args ...string) error { } func (cli *DockerCli) CmdBuild(args ...string) error { - cmd := Subcmd("build", "[CONTEXT|-]", "Build an image from a Dockerfile") + cmd := Subcmd("build", "PATH | -", "Build a new container image from the source code at PATH") if err := cmd.Parse(args); err != nil { return nil } From db47132a8ab904f58b8026aa06e8002084fe8726 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Wed, 29 May 2013 18:18:57 -0700 Subject: [PATCH 24/61] Simplified syntax of 'docker build': 'docker build PATH | -' Upstream-commit: fc864d2f0f2814be87984cefec66719c6d95d802 Component: engine --- components/engine/commands.go | 55 +++++++++++++++-------------------- 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/components/engine/commands.go b/components/engine/commands.go index 6cca487851..67b8e917f5 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -135,6 +135,10 @@ func (cli *DockerCli) CmdBuild(args ...string) error { if err := cmd.Parse(args); err != nil { return nil } + if cmd.NArg() != 1 { + cmd.Usage() + return nil + } var ( multipartBody io.Reader @@ -148,43 +152,26 @@ func (cli *DockerCli) CmdBuild(args ...string) error { w := multipart.NewWriter(buff) boundary := strings.NewReader("\r\n--" + w.Boundary() + "--\r\n") - dockerfile := "Dockerfile" - - if cmd.Arg(0) != "" && cmd.Arg(0) != "-" { - contextPath = cmd.Arg(0) - dockerfile = path.Join(cmd.Arg(0), dockerfile) - } - if cmd.Arg(0) != "-" { - f, err := os.Open(dockerfile) - if err != nil { - return err - } - defer f.Close() - file = f - } else { - contextPath = cmd.Arg(1) - file = os.Stdin - } - - // Create a FormFile multipart for the Dockerfile - if wField, err := w.CreateFormFile("Dockerfile", "Dockerfile"); err != nil { - return err - } else { - io.Copy(wField, file) - } - multipartBody = io.MultiReader(multipartBody, boundary) - compression := Bzip2 - // Create a FormFile multipart for the context if needed - if contextPath != "" { + if cmd.Arg(0) == "-" { + file = os.Stdin + } else { + // Send Dockerfile from arg/Dockerfile (deprecate later) + if f, err := os.Open(path.Join(cmd.Arg(0), "Dockerfile")); err != nil { + return err + } else { + file = f + } + // Send context from arg + // Create a FormFile multipart for the context if needed // FIXME: Use NewTempArchive in order to have the size and avoid too much memory usage? - context, err := Tar(contextPath, compression) + context, err := Tar(cmd.Arg(0), compression) if err != nil { return err } // NOTE: Do this in case '.' or '..' is input - absPath, err := filepath.Abs(contextPath) + absPath, err := filepath.Abs(cmd.Arg(0)) if err != nil { return err } @@ -194,9 +181,15 @@ func (cli *DockerCli) CmdBuild(args ...string) error { // 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) } + // Create a FormFile multipart for the Dockerfile + if wField, err := w.CreateFormFile("Dockerfile", "Dockerfile"); err != nil { + return err + } else { + io.Copy(wField, file) + } + 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"), multipartBody) From 76555eb6ccbbb8ddbb388c714419f0e2c07aa30f Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Wed, 29 May 2013 18:55:00 -0700 Subject: [PATCH 25/61] Fix issue with mkdir within docker build Upstream-commit: 9a394041270d2a8ba648f215dacc186473140552 Component: engine --- components/engine/buildfile.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/components/engine/buildfile.go b/components/engine/buildfile.go index 805ebb4fbb..b4c96e36d5 100644 --- a/components/engine/buildfile.go +++ b/components/engine/buildfile.go @@ -221,15 +221,15 @@ func (b *buildFile) CmdAdd(args string) error { origPath := path.Join(b.context, orig) destPath := path.Join(container.RootfsPath(), dest) - if err := os.MkdirAll(path.Dir(destPath), 0700); err != nil { - return err - } - fi, err := os.Stat(origPath) if err != nil { return err } if fi.IsDir() { + if err := os.MkdirAll(destPath, 0700); err != nil { + return err + } + files, err := ioutil.ReadDir(path.Join(b.context, orig)) if err != nil { return err @@ -240,6 +240,9 @@ func (b *buildFile) CmdAdd(args string) error { } } } else { + if err := os.MkdirAll(path.Dir(destPath), 0700); err != nil { + return err + } if err := utils.CopyDirectory(origPath, destPath); err != nil { return err } From f05f5b2a203dba64ff98d67a8fbd1445c72b50dc Mon Sep 17 00:00:00 2001 From: Renato Riccieri Santos Zannon Date: Thu, 30 May 2013 01:56:08 -0300 Subject: [PATCH 26/61] Add IP forwarding config to archlinux guide I had this small issue when following this guide on my Arch box, and I don't think it is specific to any configuration I have. Upstream-commit: b2084a9c599d91fa1460116ef0c8d509d3353103 Component: engine --- .../docs/sources/installation/archlinux.rst | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/components/engine/docs/sources/installation/archlinux.rst b/components/engine/docs/sources/installation/archlinux.rst index 9e3766eb26..722c150194 100644 --- a/components/engine/docs/sources/installation/archlinux.rst +++ b/components/engine/docs/sources/installation/archlinux.rst @@ -67,3 +67,21 @@ To start on system boot: :: sudo systemctl enable docker + +Network Configuration +--------------------- + +IPv4 packet forwarding is disabled by default on Arch, so internet access from inside +the container may not work. + +To enable the forwarding, run as root on the host system: + +:: + + sysctl net.ipv4.ip_forward=1 + +And, to make it persistent across reboots, enable it on the host's **/etc/sysctl.conf**: + +:: + + net.ipv4.ip_forward=1 From 5d18bff14c02ed439ae4ba09e8b5c9031c9405d6 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Wed, 29 May 2013 21:57:36 -0700 Subject: [PATCH 27/61] 'docker build': remove INSERT command (should add support for remote sources in ADD instead) Upstream-commit: 97247c5c733db355f7261ddad5223a00c33c635e Component: engine --- components/engine/buildfile.go | 39 ---------------------------------- 1 file changed, 39 deletions(-) diff --git a/components/engine/buildfile.go b/components/engine/buildfile.go index b4c96e36d5..a4ef2de0a9 100644 --- a/components/engine/buildfile.go +++ b/components/engine/buildfile.go @@ -152,45 +152,6 @@ func (b *buildFile) CmdExpose(args string) error { return b.commit("", b.config.Cmd, fmt.Sprintf("EXPOSE %v", ports)) } -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() - - cmd := b.config.Cmd - b.config.Cmd = []string{"/bin/sh", "-c", fmt.Sprintf("#(nop) INSERT %s in %s", sourceUrl, destPath)} - 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 - } - if err := b.commit(cid, cmd, fmt.Sprintf("INSERT %s in %s", sourceUrl, destPath)); err != nil { - return err - } - b.config.Cmd = cmd - return nil -} - func (b *buildFile) CmdAdd(args string) error { if b.context == "" { return fmt.Errorf("No context given. Impossible to use ADD") From 654be8b3a8a40d7d4185e61eceb2b4ba3ab98961 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 30 May 2013 13:45:39 +0000 Subject: [PATCH 28/61] if address already in use in unit tests, try a different port Upstream-commit: 2a53717e8ff01df7c58485f89845bad31e50f497 Component: engine --- components/engine/runtime_test.go | 53 ++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/components/engine/runtime_test.go b/components/engine/runtime_test.go index 384cbd1eb8..adb5e55bc7 100644 --- a/components/engine/runtime_test.go +++ b/components/engine/runtime_test.go @@ -5,9 +5,12 @@ import ( "github.com/dotcloud/docker/utils" "io" "io/ioutil" + "log" "net" "os" "os/user" + "strconv" + "strings" "sync" "testing" "time" @@ -277,24 +280,50 @@ func TestGet(t *testing.T) { } +func findAvailalblePort(runtime *Runtime, port int) (*Container, error) { + strPort := strconv.Itoa(port) + container, err := NewBuilder(runtime).Create(&Config{ + Image: GetTestImage(runtime).Id, + Cmd: []string{"sh", "-c", "echo well hello there | nc -l -p " + strPort}, + PortSpecs: []string{strPort}, + }, + ) + if err != nil { + return nil, err + } + if err := container.Start(); err != nil { + if strings.Contains(err.Error(), "address already in use") { + return nil, nil + } + return nil, err + } + return container, nil +} + // Run a container with a TCP port allocated, and test that it can receive connections on localhost func TestAllocatePortLocalhost(t *testing.T) { runtime, err := newTestRuntime() if err != nil { t.Fatal(err) } - container, err := NewBuilder(runtime).Create(&Config{ - Image: GetTestImage(runtime).Id, - Cmd: []string{"sh", "-c", "echo well hello there | nc -l -p 5555"}, - PortSpecs: []string{"5555"}, - }, - ) - if err != nil { - t.Fatal(err) - } - if err := container.Start(); err != nil { - t.Fatal(err) + port := 5554 + + var container *Container + for { + port += 1 + log.Println("Trying port", port) + t.Log("Trying port", port) + container, err = findAvailalblePort(runtime, port) + if container != nil { + break + } + if err != nil { + t.Fatal(err) + } + log.Println("Port", port, "already in use") + t.Log("Port", port, "already in use") } + defer container.Kill() setTimeout(t, "Waiting for the container to be started timed out", 2*time.Second, func() { @@ -308,7 +337,7 @@ func TestAllocatePortLocalhost(t *testing.T) { conn, err := net.Dial("tcp", fmt.Sprintf( - "localhost:%s", container.NetworkSettings.PortMapping["5555"], + "localhost:%s", container.NetworkSettings.PortMapping[strconv.Itoa(port)], ), ) if err != nil { From 2ac9914ba8a721faf80db235750f80514df58698 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 30 May 2013 14:08:26 +0000 Subject: [PATCH 29/61] always display help in the same order Upstream-commit: 2c14d3949dcad3a98980929e0cb2d2326db7d8fe Component: engine --- components/engine/commands.go | 60 +++++++++++++++++------------------ 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/components/engine/commands.go b/components/engine/commands.go index 97a249e54a..3ce5708aa1 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -73,37 +73,37 @@ 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.host, cli.port) - for cmd, description := range map[string]string{ - "attach": "Attach to a running container", - "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", - "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 _, command := range [][2]string{ + {"attach", "Attach to a running container"}, + {"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"}, + {"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, description) + help += fmt.Sprintf(" %-10.10s%s\n", command[0], command[1]) } fmt.Println(help) return nil From 3224305e04d3cd7b3adf8c1c4af8399f1cf12e2b Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Thu, 30 May 2013 11:26:47 -0700 Subject: [PATCH 30/61] * Documentation: removed 'building blocks' for now. Upstream-commit: 2ed1092dad9d2dec30945b06572befbba003ed1d Component: engine --- .../docs/sources/concepts/buildingblocks.rst | 25 ------------------- .../engine/docs/sources/concepts/index.rst | 1 - 2 files changed, 26 deletions(-) delete mode 100644 components/engine/docs/sources/concepts/buildingblocks.rst diff --git a/components/engine/docs/sources/concepts/buildingblocks.rst b/components/engine/docs/sources/concepts/buildingblocks.rst deleted file mode 100644 index 5f752ea47b..0000000000 --- a/components/engine/docs/sources/concepts/buildingblocks.rst +++ /dev/null @@ -1,25 +0,0 @@ -:title: Building Blocks -:description: An introduction to docker and standard containers? -:keywords: containers, lxc, concepts, explanation - - -Building blocks -=============== - -.. _images: - -Images ------- -An original container image. These are stored on disk and are comparable with what you normally expect from a stopped virtual machine image. Images are stored (and retrieved from) repository - -Images are stored on your local file system under /var/lib/docker/graph - - -.. _containers: - -Containers ----------- -A container is a local version of an image. It can be running or stopped, The equivalent would be a virtual machine instance. - -Containers are stored on your local file system under /var/lib/docker/containers - diff --git a/components/engine/docs/sources/concepts/index.rst b/components/engine/docs/sources/concepts/index.rst index ba1f9f4718..8b02d15d33 100644 --- a/components/engine/docs/sources/concepts/index.rst +++ b/components/engine/docs/sources/concepts/index.rst @@ -13,5 +13,4 @@ Contents: :maxdepth: 1 ../index - buildingblocks From 0a206f47a80eeb4ba11fcc6df38292355dc515d9 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Thu, 30 May 2013 11:31:49 -0700 Subject: [PATCH 31/61] Make Victor Vieux a core maintainer Upstream-commit: fc788956c5b1e3afb802d3fad1788377eea4e55a Component: engine --- components/engine/MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/components/engine/MAINTAINERS b/components/engine/MAINTAINERS index 6203feeb03..dc0d1a19f6 100644 --- a/components/engine/MAINTAINERS +++ b/components/engine/MAINTAINERS @@ -1,4 +1,5 @@ Solomon Hykes Guillaume Charmes +Victor Vieux api.go: Victor Vieux Vagrantfile: Daniel Mizyrycki From bc3ec475fa416307d3545612396afc4cb56353d3 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Thu, 30 May 2013 11:37:58 -0700 Subject: [PATCH 32/61] Remove special case for 'teams' from registry api Upstream-commit: 531b30119ab5422f9f34ebf3be1a6b6578ded9f1 Component: engine --- components/engine/docs/sources/api/registry_api.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/components/engine/docs/sources/api/registry_api.rst b/components/engine/docs/sources/api/registry_api.rst index 7034d90e27..bb8a16652d 100644 --- a/components/engine/docs/sources/api/registry_api.rst +++ b/components/engine/docs/sources/api/registry_api.rst @@ -246,7 +246,6 @@ The Index has two main purposes (along with its fancy social features): - Resolve short names (to avoid passing absolute URLs all the time) - username/projectname -> \https://registry.docker.io/users//repositories// - - team/projectname -> \https://registry.docker.io/team//repositories// - Authenticate a user as a repos owner (for a central referenced repository) 3.1 Without an Index From 0319ab95bb654fdfa49c900f46028de16b2f1393 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Thu, 30 May 2013 12:08:21 -0700 Subject: [PATCH 33/61] Add -t to docker build in order to tag resulting image Upstream-commit: 56431d3130f8a48cfb708509cbe39682f7fe841c Component: engine --- components/engine/api.go | 11 ++++++++++- components/engine/commands.go | 5 ++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/components/engine/api.go b/components/engine/api.go index 3c440d7331..621d9c82e1 100644 --- a/components/engine/api.go +++ b/components/engine/api.go @@ -650,6 +650,13 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ if err := r.ParseMultipartForm(4096); err != nil { return err } + remote := r.FormValue("t") + tag := "" + if strings.Contains(remote, ":") { + remoteParts := strings.Split(remote, ":") + tag = remoteParts[1] + remote = remoteParts[0] + } dockerfile, _, err := r.FormFile("Dockerfile") if err != nil { @@ -664,8 +671,10 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ } b := NewBuildFile(srv, utils.NewWriteFlusher(w)) - if _, err := b.Build(dockerfile, context); err != nil { + if id, err := b.Build(dockerfile, context); err != nil { fmt.Fprintf(w, "Error build: %s\n", err) + } else if remote != "" { + srv.runtime.repositories.Set(remote, tag, id, false) } return nil } diff --git a/components/engine/commands.go b/components/engine/commands.go index 67b8e917f5..c24a48f5a0 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -132,6 +132,7 @@ func (cli *DockerCli) CmdInsert(args ...string) error { func (cli *DockerCli) CmdBuild(args ...string) error { cmd := Subcmd("build", "PATH | -", "Build a new container image from the source code at PATH") + tag := cmd.String("t", "", "Tag to be applied to the resulting image") if err := cmd.Parse(args); err != nil { return nil } @@ -191,8 +192,10 @@ func (cli *DockerCli) CmdBuild(args ...string) error { } multipartBody = io.MultiReader(multipartBody, boundary) + v := &url.Values{} + v.Set("t", *tag) // Send the multipart request with correct content-type - req, err := http.NewRequest("POST", fmt.Sprintf("http://%s:%d%s", cli.host, cli.port, "/build"), multipartBody) + req, err := http.NewRequest("POST", fmt.Sprintf("http://%s:%d%s?%s", cli.host, cli.port, "/build", v.Encode()), multipartBody) if err != nil { return err } From 79331052dafade08e6e76b49daa9faeba514fe80 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Thu, 30 May 2013 12:10:54 -0700 Subject: [PATCH 34/61] Deprecate INSERT and COPY Upstream-commit: a4e6025cc1103d1ad9c86fa5d75f832526d2a7b8 Component: engine --- components/engine/buildfile.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/components/engine/buildfile.go b/components/engine/buildfile.go index a4ef2de0a9..cf8f3e8e56 100644 --- a/components/engine/buildfile.go +++ b/components/engine/buildfile.go @@ -152,6 +152,14 @@ func (b *buildFile) CmdExpose(args string) error { return b.commit("", b.config.Cmd, fmt.Sprintf("EXPOSE %v", ports)) } +func (b *buildFile) CmdInsert(args string) error { + return fmt.Errorf("INSERT has been deprecated. Please use ADD instead") +} + +func (b *buildFile) CmdCopy(args string) error { + return fmt.Errorf("COPY has been deprecated. Please use ADD instead") +} + func (b *buildFile) CmdAdd(args string) error { if b.context == "" { return fmt.Errorf("No context given. Impossible to use ADD") From 736941c2f516486ad057e730a48ce776c049d95d Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Thu, 30 May 2013 12:21:57 -0700 Subject: [PATCH 35/61] Fix issue with CMD instruction within docker build Upstream-commit: 6d2e3d2ec0dedc6c1429e87800e9f3d7e4ada095 Component: engine --- components/engine/buildfile.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/components/engine/buildfile.go b/components/engine/buildfile.go index cf8f3e8e56..3081367719 100644 --- a/components/engine/buildfile.go +++ b/components/engine/buildfile.go @@ -143,7 +143,11 @@ func (b *buildFile) CmdCmd(args string) error { utils.Debugf("Error unmarshalling: %s, using /bin/sh -c", err) cmd = []string{"/bin/sh", "-c", args} } - return b.commit("", cmd, fmt.Sprintf("CMD %v", cmd)) + if err := b.commit("", cmd, fmt.Sprintf("CMD %v", cmd)); err != nil { + return err + } + b.config.Cmd = cmd + return nil } func (b *buildFile) CmdExpose(args string) error { @@ -216,7 +220,11 @@ func (b *buildFile) CmdAdd(args string) error { return err } } - return b.commit(cid, cmd, fmt.Sprintf("ADD %s in %s", orig, dest)) + if err := b.commit(cid, cmd, fmt.Sprintf("ADD %s in %s", orig, dest)); err != nil { + return err + } + b.config.Cmd = cmd + return nil } func (b *buildFile) run() (string, error) { From ed61783c00ecdbea100a6cbff13caf161d6ffe0a Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Thu, 30 May 2013 12:28:24 -0700 Subject: [PATCH 36/61] Organize the project infrastructure: servers, dns, email etc. Upstream-commit: 43f369ea0ca5d07a1e3b6d04864ad204c3c65357 Component: engine --- components/engine/hack/infrastructure/MAINTAINERS | 2 ++ components/engine/hack/infrastructure/README.md | 5 +++++ 2 files changed, 7 insertions(+) create mode 100644 components/engine/hack/infrastructure/MAINTAINERS create mode 100644 components/engine/hack/infrastructure/README.md diff --git a/components/engine/hack/infrastructure/MAINTAINERS b/components/engine/hack/infrastructure/MAINTAINERS new file mode 100644 index 0000000000..490b0c1ea2 --- /dev/null +++ b/components/engine/hack/infrastructure/MAINTAINERS @@ -0,0 +1,2 @@ +Ken Cochrane +Jerome Petazzoni diff --git a/components/engine/hack/infrastructure/README.md b/components/engine/hack/infrastructure/README.md new file mode 100644 index 0000000000..126792a6b0 --- /dev/null +++ b/components/engine/hack/infrastructure/README.md @@ -0,0 +1,5 @@ +# Docker project infrastructure + +This directory holds all information about the technical infrastructure of the docker project; servers, dns, email, and all the corresponding tools and configuration. + +Obviously credentials should not be stored in this repo, but how to obtain and use them should be documented here. From fc9613526d732f2281157d2029ac13933c233e52 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Thu, 30 May 2013 12:35:19 -0700 Subject: [PATCH 37/61] Update docker build docs Upstream-commit: 28d5b2c15acc6e088a0abd2099a00ba1180beb3e Component: engine --- components/engine/commands.go | 4 ++-- .../sources/commandline/command/build.rst | 21 +++++-------------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/components/engine/commands.go b/components/engine/commands.go index c24a48f5a0..14491d31a1 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -131,8 +131,8 @@ func (cli *DockerCli) CmdInsert(args ...string) error { } func (cli *DockerCli) CmdBuild(args ...string) error { - cmd := Subcmd("build", "PATH | -", "Build a new container image from the source code at PATH") - tag := cmd.String("t", "", "Tag to be applied to the resulting image") + cmd := Subcmd("build", "[OPTIONS] PATH | -", "Build a new container image from the source code at PATH") + tag := cmd.String("t", "", "Tag to be applied to the resulting image in case of success") if err := cmd.Parse(args); err != nil { return nil } diff --git a/components/engine/docs/sources/commandline/command/build.rst b/components/engine/docs/sources/commandline/command/build.rst index f7df8cbbc3..81120b22d2 100644 --- a/components/engine/docs/sources/commandline/command/build.rst +++ b/components/engine/docs/sources/commandline/command/build.rst @@ -8,32 +8,21 @@ :: - Usage: docker build [CONTEXT|-] - Build a new image from a Dockerfile + Usage: docker build [OPTIONS] PATH | - + Build a new container image from the source code at PATH + -t="": Tag to be applied to the resulting image in case of success. Examples -------- .. code-block:: bash - docker build + docker build . -This will take the local Dockerfile without context +This will take the local Dockerfile .. code-block:: bash docker build - This will read a Dockerfile form Stdin without context - -.. code-block:: bash - - docker build . - -This will take the local Dockerfile and set the current directory as context - -.. code-block:: bash - - docker build - . - -This will read a Dockerfile from Stdin and set the current directory as context From 7959cb95a2c93bf0d0de38bf3d1aa724023f233c Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Thu, 30 May 2013 15:52:09 -0700 Subject: [PATCH 38/61] * Builder: keep temporary images after a build fails, to allow caching Upstream-commit: c903a6baf83b4aaa51d7198643e0eef9211c99ed Component: engine --- components/engine/buildfile.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/components/engine/buildfile.go b/components/engine/buildfile.go index 3081367719..81aea513db 100644 --- a/components/engine/buildfile.go +++ b/components/engine/buildfile.go @@ -347,10 +347,6 @@ func (b *buildFile) Build(dockerfile, context io.Reader) (string, error) { fmt.Fprintf(b.out, "===> %v\n", b.image) } 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 successful.\n===> %s\n", b.image) return b.image, nil } From 4be68db978098714e888f3faf646fab53d038bae Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Thu, 30 May 2013 16:24:26 -0700 Subject: [PATCH 39/61] * Build: never remove temporary images and containers Upstream-commit: caaea2e08f85438b7a6bee006e803f1c4351c445 Component: engine --- components/engine/buildfile.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/components/engine/buildfile.go b/components/engine/buildfile.go index 81aea513db..d9a4b5eff6 100644 --- a/components/engine/buildfile.go +++ b/components/engine/buildfile.go @@ -298,8 +298,6 @@ func (b *buildFile) commit(id string, autoCmd []string, comment string) error { } func (b *buildFile) Build(dockerfile, context io.Reader) (string, error) { - defer b.clearTmp(b.tmpContainers, b.tmpImages) - if context != nil { name, err := ioutil.TempDir("/tmp", "docker-build") if err != nil { @@ -350,9 +348,6 @@ func (b *buildFile) Build(dockerfile, context io.Reader) (string, error) { fmt.Fprintf(b.out, "Build successful.\n===> %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") } From ef88e719c07dff8d84f83693805b683dfb0f6247 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Thu, 30 May 2013 17:27:45 -0700 Subject: [PATCH 40/61] Bumped version to 0.3.4 Upstream-commit: 8d73740343778651c09160cde9661f5f387b36f4 Component: engine --- components/engine/CHANGELOG.md | 9 +++++++++ components/engine/commands.go | 2 +- components/engine/packaging/debian/changelog | 11 +++++++++++ components/engine/packaging/ubuntu/changelog | 12 ++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/components/engine/CHANGELOG.md b/components/engine/CHANGELOG.md index 4d3502d23a..a8464b5345 100644 --- a/components/engine/CHANGELOG.md +++ b/components/engine/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## 0.3.4 (2013-05-30) + + Builder: 'docker build' builds a container, layer by layer, from a source repository containing a Dockerfile + + Builder: 'docker build -t FOO' applies the tag FOO to the newly built container. + + Runtime: interactive TTYs correctly handle window resize + * Runtime: fix how configuration is merged between layers + + Remote API: split stdout and stderr on 'docker run' + + Remote API: optionally listen on a different IP and port (use at your own risk) + * Documentation: improved install instructions. + ## 0.3.3 (2013-05-23) - Registry: Fix push regression - Various bugfixes diff --git a/components/engine/commands.go b/components/engine/commands.go index 38deb1a561..0e8d0b48f2 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -28,7 +28,7 @@ import ( "unicode" ) -const VERSION = "0.3.3" +const VERSION = "0.3.4" var ( GIT_COMMIT string diff --git a/components/engine/packaging/debian/changelog b/components/engine/packaging/debian/changelog index c7a34d4869..55102dd2ac 100644 --- a/components/engine/packaging/debian/changelog +++ b/components/engine/packaging/debian/changelog @@ -1,3 +1,14 @@ +lxc-docker (0.3.4-1) UNRELEASED; urgency=low + - Builder: 'docker build' builds a container, layer by layer, from a source repository containing a Dockerfile + - Builder: 'docker build -t FOO' applies the tag FOO to the newly built container. + - Runtime: interactive TTYs correctly handle window resize + - Runtime: fix how configuration is merged between layers + - Remote API: split stdout and stderr on 'docker run' + - Remote API: optionally listen on a different IP and port (use at your own risk) + - Documentation: improved install instructions. + + -- dotCloud Thu, 30 May 2013 00:00:00 -0700 + lxc-docker (0.3.2-1) UNRELEASED; urgency=low - Runtime: Store the actual archive on commit - Registry: Improve the checksum process diff --git a/components/engine/packaging/ubuntu/changelog b/components/engine/packaging/ubuntu/changelog index c8a8c1689b..10151ed483 100644 --- a/components/engine/packaging/ubuntu/changelog +++ b/components/engine/packaging/ubuntu/changelog @@ -1,3 +1,15 @@ +lxc-docker (0.3.4-1) precise; urgency=low + - Builder: 'docker build' builds a container, layer by layer, from a source repository containing a Dockerfile + - Builder: 'docker build -t FOO' applies the tag FOO to the newly built container. + - Runtime: interactive TTYs correctly handle window resize + - Runtime: fix how configuration is merged between layers + - Remote API: split stdout and stderr on 'docker run' + - Remote API: optionally listen on a different IP and port (use at your own risk) + - Documentation: improved install instructions. + + -- dotCloud Thu, 30 May 2013 00:00:00 -0700 + + lxc-docker (0.3.3-1) precise; urgency=low - Registry: Fix push regression - Various bugfixes From 1fad9ff9126f8520b9fc55d86b7bd504efd56bca Mon Sep 17 00:00:00 2001 From: Daniel Mizyrycki Date: Fri, 31 May 2013 00:59:18 -0700 Subject: [PATCH 41/61] Packaging: Ensure dockerbuilder can build docker PPA Upstream-commit: 1040225e36c6b235d5f82e44685b2f942be68965 Component: engine --- .../engine/hack/dockerbuilder/Dockerfile | 20 +++++++++++++------ .../engine/hack/dockerbuilder/dockerbuilder | 3 ++- .../engine/hack/dockerbuilder/fake_initctl | 3 --- 3 files changed, 16 insertions(+), 10 deletions(-) delete mode 100755 components/engine/hack/dockerbuilder/fake_initctl diff --git a/components/engine/hack/dockerbuilder/Dockerfile b/components/engine/hack/dockerbuilder/Dockerfile index 8a7382e885..5f9e9c35ab 100644 --- a/components/engine/hack/dockerbuilder/Dockerfile +++ b/components/engine/hack/dockerbuilder/Dockerfile @@ -1,23 +1,31 @@ # This will build a container capable of producing an official binary build of docker and # uploading it to S3 +from ubuntu:12.04 maintainer Solomon Hykes -from ubuntu:12.10 +# Workaround the upstart issue +run dpkg-divert --local --rename --add /sbin/initctl +run ln -s /bin/true /sbin/initctl +# Enable universe and gophers PPA +run DEBIAN_FRONTEND=noninteractive apt-get install -y -q python-software-properties +run add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) universe" +run add-apt-repository -y ppa:gophers/go/ubuntu run apt-get update +# Packages required to checkout, build and upload docker run DEBIAN_FRONTEND=noninteractive apt-get install -y -q s3cmd run DEBIAN_FRONTEND=noninteractive apt-get install -y -q curl -# Packages required to checkout and build docker run curl -s -o /go.tar.gz https://go.googlecode.com/files/go1.1.linux-amd64.tar.gz run tar -C /usr/local -xzf /go.tar.gz -run echo "export PATH=$PATH:/usr/local/go/bin" > /.bashrc -run echo "export PATH=$PATH:/usr/local/go/bin" > /.bash_profile +run echo "export PATH=/usr/local/go/bin:$PATH" > /.bashrc +run echo "export PATH=/usr/local/go/bin:$PATH" > /.bash_profile run DEBIAN_FRONTEND=noninteractive apt-get install -y -q git run DEBIAN_FRONTEND=noninteractive apt-get install -y -q build-essential # Packages required to build an ubuntu package +run DEBIAN_FRONTEND=noninteractive apt-get install -y -q golang-stable run DEBIAN_FRONTEND=noninteractive apt-get install -y -q debhelper run DEBIAN_FRONTEND=noninteractive apt-get install -y -q autotools-dev -copy fake_initctl /usr/local/bin/initctl run apt-get install -y -q devscripts -add . /src +# Copy dockerbuilder files into the container +add . /src run cp /src/dockerbuilder /usr/local/bin/ && chmod +x /usr/local/bin/dockerbuilder run cp /src/s3cfg /.s3cfg cmd ["dockerbuilder"] diff --git a/components/engine/hack/dockerbuilder/dockerbuilder b/components/engine/hack/dockerbuilder/dockerbuilder index 4287e0b336..d2e4396550 100644 --- a/components/engine/hack/dockerbuilder/dockerbuilder +++ b/components/engine/hack/dockerbuilder/dockerbuilder @@ -2,7 +2,7 @@ set -x set -e -export PATH=$PATH:/usr/local/go/bin +export PATH=/usr/local/go/bin:$PATH PACKAGE=github.com/dotcloud/docker @@ -36,5 +36,6 @@ else fi if [ -z "$NO_UBUNTU" ]; then + export PATH=`echo $PATH | sed 's#/usr/local/go/bin:##g'` (cd packaging/ubuntu && make ubuntu) fi diff --git a/components/engine/hack/dockerbuilder/fake_initctl b/components/engine/hack/dockerbuilder/fake_initctl deleted file mode 100755 index 14c46c8e94..0000000000 --- a/components/engine/hack/dockerbuilder/fake_initctl +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -echo Whatever you say, man From 0dcec39d12b15a16f214c78ba51237c7a308841c Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Fri, 31 May 2013 14:40:09 +0000 Subject: [PATCH 42/61] add -t parameter in the doc Upstream-commit: 2baea2487936c3d385671d25ab3ef1b09f9007cc Component: engine --- components/engine/docs/sources/api/docker_remote_api.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/components/engine/docs/sources/api/docker_remote_api.rst b/components/engine/docs/sources/api/docker_remote_api.rst index bd87dc7a03..66e8348e72 100644 --- a/components/engine/docs/sources/api/docker_remote_api.rst +++ b/components/engine/docs/sources/api/docker_remote_api.rst @@ -826,6 +826,7 @@ Build an image from Dockerfile via stdin {{ STREAM }} + :query t: tag to be applied to the resulting image in case of success :statuscode 200: no error :statuscode 500: server error From 3efe0a345bd320feb4db0f13e5f8b44b1bbcea25 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Fri, 31 May 2013 15:34:23 +0000 Subject: [PATCH 43/61] returns an error if the container we want to attach is not running Upstream-commit: 468e4c4b565d25b03c68ce2ab31f9a52f7b3398a Component: engine --- components/engine/api.go | 2 ++ components/engine/docs/sources/api/docker_remote_api.rst | 1 + components/engine/server.go | 4 +++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/components/engine/api.go b/components/engine/api.go index 621d9c82e1..e6ac49ad28 100644 --- a/components/engine/api.go +++ b/components/engine/api.go @@ -45,6 +45,8 @@ func httpError(w http.ResponseWriter, err error) { http.Error(w, err.Error(), http.StatusNotFound) } else if strings.HasPrefix(err.Error(), "Bad parameter") { http.Error(w, err.Error(), http.StatusBadRequest) + } else if strings.HasPrefix(err.Error(), "Impossible") { + http.Error(w, err.Error(), http.StatusNotAcceptable) } else { http.Error(w, err.Error(), http.StatusInternalServerError) } diff --git a/components/engine/docs/sources/api/docker_remote_api.rst b/components/engine/docs/sources/api/docker_remote_api.rst index bd87dc7a03..98b0005cda 100644 --- a/components/engine/docs/sources/api/docker_remote_api.rst +++ b/components/engine/docs/sources/api/docker_remote_api.rst @@ -132,6 +132,7 @@ Create a container :jsonparam config: the container's configuration :statuscode 201: no error :statuscode 404: no such container + :statuscode 406: impossible to attach (container not running) :statuscode 500: server error diff --git a/components/engine/server.go b/components/engine/server.go index 0440b0a8a4..90ec79986c 100644 --- a/components/engine/server.go +++ b/components/engine/server.go @@ -790,7 +790,6 @@ func (srv *Server) ContainerAttach(name string, logs, stream, stdin, stdout, std if container == nil { return fmt.Errorf("No such container: %s", name) } - //logs if logs { if stdout { @@ -816,6 +815,9 @@ func (srv *Server) ContainerAttach(name string, logs, stream, stdin, stdout, std if container.State.Ghost { return fmt.Errorf("Impossible to attach to a ghost container") } + if !container.State.Running { + return fmt.Errorf("Impossible to attach to a stopped container, start it first") + } var ( cStdin io.ReadCloser From 86f679c0128d18eb3cbd03c04961a00c60f028cc Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Fri, 31 May 2013 12:19:49 -0700 Subject: [PATCH 44/61] =?UTF-8?q?Fix=20minor=20documentation=20error=20in?= =?UTF-8?q?=20=E2=80=98Running=20Redis=20Service=E2=80=99=20example=20Upst?= =?UTF-8?q?ream-commit:=20fd0c501e6d65b665cba87f3449e02a722d90e6b1=20Compo?= =?UTF-8?q?nent:=20engine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../engine/docs/sources/examples/running_redis_service.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/engine/docs/sources/examples/running_redis_service.rst b/components/engine/docs/sources/examples/running_redis_service.rst index 018b061707..4b5d161e61 100644 --- a/components/engine/docs/sources/examples/running_redis_service.rst +++ b/components/engine/docs/sources/examples/running_redis_service.rst @@ -34,7 +34,7 @@ Snapshot the installation .. code-block:: bash - docker ps -a # grab the container id (this will be the last one in the list) + docker ps -a # grab the container id (this will be the first one in the list) docker commit /redis Run the service From e420edad89ba24134ab2c11956bfb6e5aa9fbd5a Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Fri, 31 May 2013 12:19:57 -0700 Subject: [PATCH 45/61] Add Daniel Gasienica to AUTHORS Upstream-commit: 766a2db0d94d0f7cd8bdb71762476893a4df4cc1 Component: engine --- components/engine/AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/components/engine/AUTHORS b/components/engine/AUTHORS index fdddedde15..1599a1d0e1 100644 --- a/components/engine/AUTHORS +++ b/components/engine/AUTHORS @@ -15,6 +15,7 @@ Brian McCallister Bruno Bigras Caleb Spare Charles Hooper +Daniel Gasienica Daniel Mizyrycki Daniel Robinson Daniel Von Fange From ca771dfaab506a13c470c24ba4d40621f3935041 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Fri, 31 May 2013 22:25:48 -0700 Subject: [PATCH 46/61] * Runtime: pass a guaranteed environment to bsdtar for predictable behavior without depending on the underlying host configuration. Upstream-commit: 561ceac55d5821a00258934cf9dc215278e3ecfd Component: engine --- components/engine/archive.go | 3 +++ components/engine/packaging/ubuntu/docker.upstart | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/components/engine/archive.go b/components/engine/archive.go index 4120a52c1d..06466627a1 100644 --- a/components/engine/archive.go +++ b/components/engine/archive.go @@ -54,6 +54,9 @@ func Tar(path string, compression Compression) (io.Reader, error) { func Untar(archive io.Reader, path string) error { cmd := exec.Command("bsdtar", "-f", "-", "-C", path, "-x") cmd.Stdin = archive + // Hardcode locale environment for predictable outcome regardless of host configuration. + // (see https://github.com/dotcloud/docker/issues/355) + cmd.Env = []string{"LANG=en_US.utf-8", "LC_ALL=en_US.utf-8"} output, err := cmd.CombinedOutput() if err != nil { return fmt.Errorf("%s: %s", err, output) diff --git a/components/engine/packaging/ubuntu/docker.upstart b/components/engine/packaging/ubuntu/docker.upstart index 07e7e8a890..2bd5565ee7 100644 --- a/components/engine/packaging/ubuntu/docker.upstart +++ b/components/engine/packaging/ubuntu/docker.upstart @@ -5,6 +5,5 @@ stop on starting rc RUNLEVEL=[016] respawn script - # FIXME: docker should not depend on the system having en_US.UTF-8 - LC_ALL='en_US.UTF-8' /usr/bin/docker -d + /usr/bin/docker -d end script From 2fce4aa919cfc75744efc5e8961b9d8f05f2329f Mon Sep 17 00:00:00 2001 From: Jon Wedaman Date: Sat, 1 Jun 2013 21:48:32 -0400 Subject: [PATCH 47/61] Spelling correction in docs Upstream-commit: 7f65bf508e5930df48e3e3de2ed9a5a62a66446c Component: engine --- components/engine/docs/website/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/engine/docs/website/index.html b/components/engine/docs/website/index.html index d441ed8d78..bc3e2d0271 100644 --- a/components/engine/docs/website/index.html +++ b/components/engine/docs/website/index.html @@ -270,7 +270,7 @@
  • Filesystem isolation: each process container runs in a completely separate root filesystem.
  • Resource isolation: system resources like cpu and memory can be allocated differently to each process container, using cgroups.
  • Network isolation: each process container runs in its own network namespace, with a virtual interface and IP address of its own.
  • -
  • Copy-on-write: root filesystems are created using copy-on-write, which makes deployment extremeley fast, memory-cheap and disk-cheap.
  • +
  • Copy-on-write: root filesystems are created using copy-on-write, which makes deployment extremely fast, memory-cheap and disk-cheap.
  • Logging: the standard streams (stdout/stderr/stdin) of each process container is collected and logged for real-time or batch retrieval.
  • Change management: changes to a container's filesystem can be committed into a new image and re-used to create more containers. No templating or manual configuration required.
  • Interactive shell: docker can allocate a pseudo-tty and attach to the standard input of any container, for example to run a throwaway interactive shell.
  • From 76d5aac68b3e8d86294fcda49ec81ad4a108d62d Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Sat, 1 Jun 2013 21:25:51 -0700 Subject: [PATCH 48/61] Add `make server` command to preview docs Upstream-commit: b4df0b17afef027e88f0536cbfc9518e04f62eec Component: engine --- components/engine/docs/Makefile | 4 ++++ components/engine/docs/README.md | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/components/engine/docs/Makefile b/components/engine/docs/Makefile index 26168b6f38..dcbf111c29 100644 --- a/components/engine/docs/Makefile +++ b/components/engine/docs/Makefile @@ -6,6 +6,7 @@ SPHINXOPTS = SPHINXBUILD = sphinx-build PAPER = BUILDDIR = _build +PYTHON = python # Internal variables. PAPEROPT_a4 = -D latex_paper_size=a4 @@ -38,6 +39,7 @@ help: # @echo " linkcheck to check all external links for integrity" # @echo " doctest to run all doctests embedded in the documentation (if enabled)" @echo " docs to build the docs and copy the static files to the outputdir" + @echo " server to serve the docs in your browser under \`http://localhost:8000\`" @echo " publish to publish the app to dotcloud" clean: @@ -49,6 +51,8 @@ docs: @echo @echo "Build finished. The documentation pages are now in $(BUILDDIR)/html." +server: + @cd $(BUILDDIR)/html; $(PYTHON) -m SimpleHTTPServer 8000 site: cp -r website $(BUILDDIR)/ diff --git a/components/engine/docs/README.md b/components/engine/docs/README.md index e1ca45b085..ef24c3fb1d 100644 --- a/components/engine/docs/README.md +++ b/components/engine/docs/README.md @@ -23,7 +23,7 @@ Usage * change the .rst files with your favorite editor to your liking * run *make docs* to clean up old files and generate new ones * your static website can now be found in the _build dir -* to preview what you have generated, cd into _build/html and then run 'python -m SimpleHTTPServer 8000' +* to preview what you have generated run `make server` and open in your favorite browser. Working using github's file editor ---------------------------------- From fef5363d7dac273fef50a341194f38ce50e873f6 Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Sat, 1 Jun 2013 21:26:18 -0700 Subject: [PATCH 49/61] Add Mac OS X instructions for doc tools Upstream-commit: 3ca9c11110ff5068fd453a3e8aa0b39ee26d363c Component: engine --- components/engine/docs/README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/components/engine/docs/README.md b/components/engine/docs/README.md index ef24c3fb1d..54588e995d 100644 --- a/components/engine/docs/README.md +++ b/components/engine/docs/README.md @@ -14,8 +14,10 @@ Installation ------------ * Work in your own fork of the code, we accept pull requests. -* Install sphinx: ``pip install sphinx`` -* Install sphinx httpdomain contrib package ``sphinxcontrib-httpdomain`` +* Install sphinx: `pip install sphinx` + * Mac OS X: `[sudo] pip-2.7 install sphinx`) +* Install sphinx httpdomain contrib package: `pip install sphinxcontrib-httpdomain` + * Mac OS X: `[sudo] pip-2.7 install sphinxcontrib-httpdomain` * If pip is not available you can probably install it using your favorite package manager as **python-pip** Usage From 4902d73b72aeee15fd6475caf8dd3caec132cfda Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Sat, 1 Jun 2013 21:26:54 -0700 Subject: [PATCH 50/61] Make style consistent Upstream-commit: 01ce63aacdd975130244f4be70bc90736e85d457 Component: engine --- components/engine/docs/README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/components/engine/docs/README.md b/components/engine/docs/README.md index 54588e995d..74ab2bd0cd 100644 --- a/components/engine/docs/README.md +++ b/components/engine/docs/README.md @@ -22,14 +22,14 @@ Installation Usage ----- -* change the .rst files with your favorite editor to your liking -* run *make docs* to clean up old files and generate new ones -* your static website can now be found in the _build dir -* to preview what you have generated run `make server` and open in your favorite browser. +* Change the `.rst` files with your favorite editor to your liking. +* Run `make docs` to clean up old files and generate new ones. +* Your static website can now be found in the `_build` directory. +* To preview what you have generated run `make server` and open in your favorite browser. -Working using github's file editor +Working using GitHub's file editor ---------------------------------- -Alternatively, for small changes and typo's you might want to use github's built in file editor. It allows +Alternatively, for small changes and typo's you might want to use GitHub's built in file editor. It allows you to preview your changes right online. Just be carefull not to create many commits. Images @@ -74,4 +74,4 @@ Guides on using sphinx * Code examples - Start without $, so it's easy to copy and paste. \ No newline at end of file + Start without $, so it's easy to copy and paste. From cf5d33839b50cb6c742187d589bae22540f527ef Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Sat, 1 Jun 2013 21:27:27 -0700 Subject: [PATCH 51/61] Add more tags Upstream-commit: e3fd61ad74521b1a94502cf8dcc7c450f035c168 Component: engine --- components/engine/docs/sources/examples/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/engine/docs/sources/examples/index.rst b/components/engine/docs/sources/examples/index.rst index 7eb2ecbe94..3a8e01fe03 100644 --- a/components/engine/docs/sources/examples/index.rst +++ b/components/engine/docs/sources/examples/index.rst @@ -1,6 +1,6 @@ :title: Docker Examples :description: Examples on how to use Docker -:keywords: docker, hello world, examples +:keywords: docker, hello world, python, couch, couchdb, redis, ssh, sshd, examples From aee770cf4d9cae330f93e77d728fd0d1125da82a Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Sat, 1 Jun 2013 21:55:01 -0700 Subject: [PATCH 52/61] Fix typo Upstream-commit: f6f345b1fe0ecc1adba449b0078d96388dd48892 Component: engine --- components/engine/docs/sources/api/index.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/engine/docs/sources/api/index.rst b/components/engine/docs/sources/api/index.rst index 4d8ff3fe67..85770f484e 100644 --- a/components/engine/docs/sources/api/index.rst +++ b/components/engine/docs/sources/api/index.rst @@ -2,8 +2,8 @@ :description: docker documentation :keywords: docker, ipa, documentation -API's -============= +APIs +==== This following : From 445dfaf8b16ee3189dbb0f51e85c94728c1cef00 Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Sat, 1 Jun 2013 22:02:24 -0700 Subject: [PATCH 53/61] Use em dash in title Upstream-commit: 23452f1573e7887b638a4e69a4cf90d757921885 Component: engine --- components/engine/docs/sources/concepts/introduction.rst | 4 ++-- components/engine/docs/sources/index.rst | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/engine/docs/sources/concepts/introduction.rst b/components/engine/docs/sources/concepts/introduction.rst index fcdd37a791..7251b51786 100644 --- a/components/engine/docs/sources/concepts/introduction.rst +++ b/components/engine/docs/sources/concepts/introduction.rst @@ -5,8 +5,8 @@ Introduction ============ -Docker - The Linux container runtime ------------------------------------- +Docker -- The Linux container runtime +------------------------------------- Docker complements LXC with a high-level API which operates at the process level. It runs unix processes with strong guarantees of isolation and repeatability across servers. diff --git a/components/engine/docs/sources/index.rst b/components/engine/docs/sources/index.rst index 172f82083c..3e66fde1fb 100644 --- a/components/engine/docs/sources/index.rst +++ b/components/engine/docs/sources/index.rst @@ -7,8 +7,8 @@ Introduction ============ -Docker - The Linux container runtime ------------------------------------- +Docker -- The Linux container runtime +------------------------------------- Docker complements LXC with a high-level API which operates at the process level. It runs unix processes with strong guarantees of isolation and repeatability across servers. From 74278bf53f67340b6348dcaff16c9de9c9f54bae Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Sat, 1 Jun 2013 22:03:12 -0700 Subject: [PATCH 54/61] Use title case for consistency Upstream-commit: 2935ca7ee2879723c786b86ee87cc1be26dad7b8 Component: engine --- .../engine/docs/sources/contributing/devenvironment.rst | 4 ++-- components/engine/docs/sources/examples/running_examples.rst | 2 +- components/engine/docs/sources/use/basics.rst | 4 ++-- components/engine/docs/sources/use/workingwithrepository.rst | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/components/engine/docs/sources/contributing/devenvironment.rst b/components/engine/docs/sources/contributing/devenvironment.rst index 0d202596c8..b5742c780a 100644 --- a/components/engine/docs/sources/contributing/devenvironment.rst +++ b/components/engine/docs/sources/contributing/devenvironment.rst @@ -1,8 +1,8 @@ -:title: Setting up a dev environment +:title: Setting Up a Dev Environment :description: Guides on how to contribute to docker :keywords: Docker, documentation, developers, contributing, dev environment -Setting up a dev environment +Setting Up a Dev Environment ============================ Instructions that have been verified to work on Ubuntu 12.10, diff --git a/components/engine/docs/sources/examples/running_examples.rst b/components/engine/docs/sources/examples/running_examples.rst index 3d2593c710..b6d6444aac 100644 --- a/components/engine/docs/sources/examples/running_examples.rst +++ b/components/engine/docs/sources/examples/running_examples.rst @@ -4,7 +4,7 @@ .. _running_examples: -Running The Examples +Running the Examples -------------------- All the examples assume your machine is running the docker daemon. To run the docker daemon in the background, simply type: diff --git a/components/engine/docs/sources/use/basics.rst b/components/engine/docs/sources/use/basics.rst index 378028703c..444b74db51 100644 --- a/components/engine/docs/sources/use/basics.rst +++ b/components/engine/docs/sources/use/basics.rst @@ -3,8 +3,8 @@ :keywords: Examples, Usage, basic commands, docker, documentation, examples -The basics -============= +The Basics +========== Starting Docker --------------- diff --git a/components/engine/docs/sources/use/workingwithrepository.rst b/components/engine/docs/sources/use/workingwithrepository.rst index 9a2f96cf0d..db40245374 100644 --- a/components/engine/docs/sources/use/workingwithrepository.rst +++ b/components/engine/docs/sources/use/workingwithrepository.rst @@ -4,8 +4,8 @@ .. _working_with_the_repository: -Working with the repository -============================ +Working with the Repository +=========================== Top-level repositories and user repositories From a6d08b401db4eac7c46d28cf4345159a83f2445b Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Sat, 1 Jun 2013 22:03:28 -0700 Subject: [PATCH 55/61] Name examples consistently Upstream-commit: 157547845acd8a0633df72e01d22bad9cbec578b Component: engine --- .../engine/docs/sources/examples/couchdb_data_volumes.rst | 4 ++-- components/engine/docs/sources/examples/python_web_app.rst | 4 ++-- .../engine/docs/sources/examples/running_redis_service.rst | 4 ++-- .../engine/docs/sources/examples/running_ssh_service.rst | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/components/engine/docs/sources/examples/couchdb_data_volumes.rst b/components/engine/docs/sources/examples/couchdb_data_volumes.rst index 1b1d7ff79c..d6babe557f 100644 --- a/components/engine/docs/sources/examples/couchdb_data_volumes.rst +++ b/components/engine/docs/sources/examples/couchdb_data_volumes.rst @@ -4,8 +4,8 @@ .. _running_couchdb_service: -Create a CouchDB service -======================== +CouchDB Service +=============== .. include:: example_header.inc diff --git a/components/engine/docs/sources/examples/python_web_app.rst b/components/engine/docs/sources/examples/python_web_app.rst index 952ef62e33..8a4ca70750 100644 --- a/components/engine/docs/sources/examples/python_web_app.rst +++ b/components/engine/docs/sources/examples/python_web_app.rst @@ -4,8 +4,8 @@ .. _python_web_app: -Building a python web app -========================= +Python Web App +============== .. include:: example_header.inc diff --git a/components/engine/docs/sources/examples/running_redis_service.rst b/components/engine/docs/sources/examples/running_redis_service.rst index 4b5d161e61..48d083aa8f 100644 --- a/components/engine/docs/sources/examples/running_redis_service.rst +++ b/components/engine/docs/sources/examples/running_redis_service.rst @@ -4,8 +4,8 @@ .. _running_redis_service: -Create a redis service -====================== +Redis Service +============= .. include:: example_header.inc diff --git a/components/engine/docs/sources/examples/running_ssh_service.rst b/components/engine/docs/sources/examples/running_ssh_service.rst index b262266dec..6183c3a55d 100644 --- a/components/engine/docs/sources/examples/running_ssh_service.rst +++ b/components/engine/docs/sources/examples/running_ssh_service.rst @@ -4,8 +4,8 @@ .. _running_ssh_service: -Create an ssh daemon service -============================ +SSH Daemon Service +================== .. include:: example_header.inc From 657224f8b45f9144d002f9f7a7448389d88ed668 Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Sat, 1 Jun 2013 22:03:41 -0700 Subject: [PATCH 56/61] Use code blocks Upstream-commit: 4fb9a6eafb981ed66fe547fe29c11525f40d0640 Component: engine --- components/engine/docs/sources/use/workingwithrepository.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/engine/docs/sources/use/workingwithrepository.rst b/components/engine/docs/sources/use/workingwithrepository.rst index db40245374..6fccc01a98 100644 --- a/components/engine/docs/sources/use/workingwithrepository.rst +++ b/components/engine/docs/sources/use/workingwithrepository.rst @@ -14,9 +14,9 @@ Top-level repositories and user repositories Generally, there are two types of repositories: Top-level repositories which are controlled by the people behind Docker, and user repositories. -* Top-level repositories can easily be recognized by not having a / (slash) in their name. These repositories can +* Top-level repositories can easily be recognized by not having a ``/`` (slash) in their name. These repositories can generally be trusted. -* User repositories always come in the form of /. This is what your published images will look like. +* User repositories always come in the form of ``/``. This is what your published images will look like. * User images are not checked, it is therefore up to you whether or not you trust the creator of this image. From 409c1d534a3fba127fbaab5fd8783b940abccef3 Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Sat, 1 Jun 2013 21:53:22 -0700 Subject: [PATCH 57/61] Add Node.js web app example using CentOS Upstream-commit: e9ffc1e49998d42f37b39cd23b56b73f7dc0e3da Component: engine --- .../engine/docs/sources/examples/index.rst | 3 +- .../docs/sources/examples/nodejs_web_app.rst | 225 ++++++++++++++++++ 2 files changed, 227 insertions(+), 1 deletion(-) create mode 100644 components/engine/docs/sources/examples/nodejs_web_app.rst diff --git a/components/engine/docs/sources/examples/index.rst b/components/engine/docs/sources/examples/index.rst index 3a8e01fe03..d017f641b1 100644 --- a/components/engine/docs/sources/examples/index.rst +++ b/components/engine/docs/sources/examples/index.rst @@ -1,6 +1,6 @@ :title: Docker Examples :description: Examples on how to use Docker -:keywords: docker, hello world, python, couch, couchdb, redis, ssh, sshd, examples +:keywords: docker, hello world, node, nodejs, python, couch, couchdb, redis, ssh, sshd, examples @@ -16,6 +16,7 @@ Contents: hello_world hello_world_daemon python_web_app + nodejs_web_app running_redis_service running_ssh_service couchdb_data_volumes diff --git a/components/engine/docs/sources/examples/nodejs_web_app.rst b/components/engine/docs/sources/examples/nodejs_web_app.rst new file mode 100644 index 0000000000..7c1df83776 --- /dev/null +++ b/components/engine/docs/sources/examples/nodejs_web_app.rst @@ -0,0 +1,225 @@ +:title: Running a Node.js app on CentOS +:description: Installing and running a Node.js app on CentOS +:keywords: docker, example, package installation, node, centos + +.. _nodejs_web_app: + +Node.js Web App +=============== + +.. include:: example_header.inc + +The goal of this example is to show you how you can build your own docker images +from a parent image using a ``Dockerfile`` . We will do that by making a simple +Node.js hello world web application running on CentOS. + +Create Node.js app +++++++++++++++++++ + +First, create a ``package.json`` file that describes your app and its +dependencies: + +.. code-block:: json + + { + "name": "docker-centos-hello", + "private": true, + "version": "0.0.1", + "description": "Node.js Hello World app on CentOS using docker", + "author": "Daniel Gasienica ", + "dependencies": { + "express": "3.2.4" + } + } + +Then, create an ``index.js`` file that defines a web app using the +`Express.js `_ framework: + +.. code-block:: javascript + + var express = require('express'); + + // Constants + var PORT = 8080; + + // App + var app = express(); + app.get('/', function (req, res) { + res.send('Hello World\n'); + }); + + app.listen(PORT) + console.log('Running on http://localhost:' + PORT); + + +In the next steps, we’ll look at how you can run this app inside a CentOS +container using docker. First, you’ll need to build a docker image of your app. + +Creating a ``Dockerfile`` ++++++++++++++++++++++++++ + +Create an empty file called ``Dockerfile``: + +.. code-block:: bash + + touch Dockerfile + +Open the ``Dockerfile`` in your favorite text editor and add the following line +that defines the version of docker the image requires to build +(this example uses docker 0.3.4): + +.. code-block:: bash + + # DOCKER-VERSION 0.3.4 + +Next, define the parent image you want to use to build your own image on top of. +Here, we’ll use `CentOS `_ (tag: ``6.4``) +available on the `docker index`_: + +.. code-block:: bash + + FROM centos:6.4 + +Since we’re building a Node.js app, you’ll have to install Node.js as well as +npm on your CentOS image. Node.js is required to run your app and npm to install +your app’s dependencies defined in ``package.json``. +To install the right package for CentOS, we’ll use the instructions from the +`Node.js wiki`_: + +.. code-block:: bash + + # Enable EPEL for Node.js + RUN rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm + # Install Node.js and npm + RUN yum install -y npm-1.2.17-5.el6 + +To bundle your app’s source code inside the docker image, use the ``ADD`` +command: + +.. code-block:: bash + + # Bundle app source + ADD . /src + +Your app binds to port ``8080`` so you’ll use the ``EXPOSE`` command to have it +mapped by the docker daemon: + +.. code-block:: bash + + EXPOSE 8080 + +Last but not least, define the command to run your app using ``CMD`` which +defines your runtime, i.e. ``node``, and the path to our app, i.e. +``src/index.js`` (see the step where we added the source to the container): + +.. code-block:: bash + + CMD ["node", "/src/index.js"] + +Your ``Dockerfile`` should now look like this: + +.. code-block:: bash + + + # DOCKER-VERSION 0.3.4 + FROM centos:6.4 + + # Enable EPEL for Node.js + RUN rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm + # Install Node.js and npm + RUN yum install -y npm-1.2.17-5.el6 + + # Bundle app source + ADD . /src + EXPOSE 8080 + CMD ["node", "/src/index.js"] + + +Building your image ++++++++++++++++++++ + +Go to the directory that has your ``Dockerfile`` and run the following command +to build a docker image. The ``-t`` flag let’s you tag your image so it’s easier +to find later using the ``docker images`` command: + +.. code-block:: bash + + docker build -t /centos-node-hello . + +Your image will now be listed by docker: + +.. code-block:: bash + + docker images + + > # Example + > REPOSITORY TAG ID CREATED + > centos 6.4 539c0211cd76 8 weeks ago + > gasi/centos-node-hello latest d64d3505b0d2 2 hours ago + + +Run the image ++++++++++++++ + +Running your image with ``-d`` runs the container in detached mode, leaving the +container running in the background. Run the image you previously built: + +.. code-block:: bash + + docker run -d /centos-node-hello + +Print the output of your app: + +.. code-block:: bash + + # Get container ID + docker ps + + # Print app output + docker logs + + > # Example + > Running on http://localhost:8080 + + +Test +++++ + +To test your app, get the the port of your app that docker mapped: + +.. code-block:: bash + + docker ps + + > # Example + > ID IMAGE COMMAND ... PORTS + > ecce33b30ebf gasi/centos-node-hello:latest node /src/index.js 49160->8080 + +In the example above, docker mapped the ``8080`` port of the container to +``49160``. + +Now you can call your app using ``curl`` (install if needed via: +``sudo apt-get install curl``): + +.. code-block:: bash + + curl -i localhost:49160 + + > HTTP/1.1 200 OK + > X-Powered-By: Express + > Content-Type: text/html; charset=utf-8 + > Content-Length: 12 + > Date: Sun, 02 Jun 2013 03:53:22 GMT + > Connection: keep-alive + > + > Hello World + +We hope this tutorial helped you get up and running with Node.js and CentOS on +docker. You can get the full source code at +https://github.com/gasi/docker-node-hello. + +Continue to :ref:`running_redis_service`. + + +.. _Node.js wiki: https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager#rhelcentosscientific-linux-6 +.. _docker index: https://index.docker.io/ From a432f97e17cde74e820507acfe7cd6775259d45a Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Sat, 1 Jun 2013 22:16:26 -0700 Subject: [PATCH 58/61] Add link at the beginning Upstream-commit: 464765b940c8194c302b89891dc06b8fcc1b37ff Component: engine --- components/engine/docs/sources/examples/nodejs_web_app.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/engine/docs/sources/examples/nodejs_web_app.rst b/components/engine/docs/sources/examples/nodejs_web_app.rst index 7c1df83776..56dab0c9aa 100644 --- a/components/engine/docs/sources/examples/nodejs_web_app.rst +++ b/components/engine/docs/sources/examples/nodejs_web_app.rst @@ -11,7 +11,8 @@ Node.js Web App The goal of this example is to show you how you can build your own docker images from a parent image using a ``Dockerfile`` . We will do that by making a simple -Node.js hello world web application running on CentOS. +Node.js hello world web application running on CentOS. You can get the full +source code at https://github.com/gasi/docker-node-hello. Create Node.js app ++++++++++++++++++ From 1731739b248eccff287875e21e23b6f8c524f61f Mon Sep 17 00:00:00 2001 From: Sam J Sharpe Date: Sun, 2 Jun 2013 22:40:56 +0100 Subject: [PATCH 59/61] Removes a brace in the description of the wait command Upstream-commit: ca5ae266b762d34075524d869e27f0daaa79265c Component: engine --- components/engine/commands.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/engine/commands.go b/components/engine/commands.go index 7dd835856f..76b70cd218 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -102,7 +102,7 @@ func (cli *DockerCli) CmdHelp(args ...string) error { {"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"}, + {"wait", "Block until a container stops, then print its exit code"}, } { help += fmt.Sprintf(" %-10.10s%s\n", command[0], command[1]) } From 43b70fa4981471845861fb3ee6133350838a2f4c Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Sun, 2 Jun 2013 20:10:22 -0700 Subject: [PATCH 60/61] Document installation of npm dependencies /ht @grigio Upstream-commit: 82dadc200593e39f0979159d46afccf64f1e7a83 Component: engine --- .../engine/docs/sources/examples/nodejs_web_app.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/components/engine/docs/sources/examples/nodejs_web_app.rst b/components/engine/docs/sources/examples/nodejs_web_app.rst index 56dab0c9aa..376dc5c286 100644 --- a/components/engine/docs/sources/examples/nodejs_web_app.rst +++ b/components/engine/docs/sources/examples/nodejs_web_app.rst @@ -102,6 +102,13 @@ command: # Bundle app source ADD . /src +Install your app dependencies using npm: + +.. code-block:: bash + + # Install app dependencies + RUN cd /src; npm install + Your app binds to port ``8080`` so you’ll use the ``EXPOSE`` command to have it mapped by the docker daemon: @@ -132,6 +139,9 @@ Your ``Dockerfile`` should now look like this: # Bundle app source ADD . /src + # Install app dependencies + RUN cd /src; npm install + EXPOSE 8080 CMD ["node", "/src/index.js"] From d6fb39728117f6777b1101435a94166a17454ae0 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Sun, 2 Jun 2013 23:42:18 -0700 Subject: [PATCH 61/61] Meta: added Guillaume as primary maintainer for tty code Upstream-commit: e42eb7fa8c22e7451e06c28d9125fc7534239c89 Component: engine --- components/engine/term/MAINTAINERS | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 components/engine/term/MAINTAINERS diff --git a/components/engine/term/MAINTAINERS b/components/engine/term/MAINTAINERS new file mode 100644 index 0000000000..8df21a4601 --- /dev/null +++ b/components/engine/term/MAINTAINERS @@ -0,0 +1,2 @@ +Guillaume Charmes +Solomon Hykes