diff --git a/.mailmap b/.mailmap index 83c18fa29c..1f38e55e28 100644 --- a/.mailmap +++ b/.mailmap @@ -2,7 +2,7 @@ -Guillaume J. Charmes creack +Guillaume J. Charmes @@ -16,4 +16,6 @@ Tim Terhorst Andy Smith + +Thatcher Peskens diff --git a/AUTHORS b/AUTHORS index e8979aac6b..e7c6834cf4 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,24 +1,34 @@ +Al Tobey +Alexey Shamrin Andrea Luzzardi Andy Rothfusz Andy Smith Antony Messerli +Barry Allard +Brandon Liu Brian McCallister +Bruno Bigras Caleb Spare Charles Hooper Daniel Mizyrycki Daniel Robinson +Daniel Von Fange Dominik Honnef Don Spaulding +Dr Nic Williams +Evan Wies ezbercih Flavio Castelli Francisco Souza Frederick F. Kautz IV Guillaume J. Charmes +Harley Laue Hunter Blanks Jeff Lindsay Jeremy Grosser Joffrey F John Costa +Jonas Pfenniger Jonathan Rudenberg Julien Barbier Jérôme Petazzoni @@ -27,8 +37,11 @@ Kevin J. Lynagh Louis Opter Maxim Treskin Mikhail Sobolev +Nate Jones Nelson Chen Niall O'Higgins +odk- +Paul Bowsher Paul Hammond Piotr Bogdan Robert Obryk @@ -38,6 +51,8 @@ Silas Sewell Solomon Hykes Sridhar Ratnakumar Thatcher Peskens +Thomas Bikeev +Tianon Gravi Tim Terhorst Troy Howard unclejack diff --git a/api.go b/api.go index 8df3291357..8984d00cd9 100644 --- a/api.go +++ b/api.go @@ -4,8 +4,8 @@ import ( "encoding/json" "fmt" "github.com/dotcloud/docker/auth" + "github.com/dotcloud/docker/utils" "github.com/gorilla/mux" - "github.com/shin-/cookiejar" "io" "log" "net/http" @@ -34,6 +34,8 @@ func parseForm(r *http.Request) error { func httpError(w http.ResponseWriter, err error) { if strings.HasPrefix(err.Error(), "No such") { http.Error(w, err.Error(), http.StatusNotFound) + } else if strings.HasPrefix(err.Error(), "Bad parameter") { + http.Error(w, err.Error(), http.StatusBadRequest) } else { http.Error(w, err.Error(), http.StatusInternalServerError) } @@ -44,12 +46,18 @@ func writeJson(w http.ResponseWriter, b []byte) { w.Write(b) } -func getAuth(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - config := &auth.AuthConfig{ - Username: srv.runtime.authConfig.Username, - Email: srv.runtime.authConfig.Email, +func getBoolParam(value string) (bool, error) { + if value == "1" || strings.ToLower(value) == "true" { + return true, nil } - b, err := json.Marshal(config) + if value == "" || value == "0" || strings.ToLower(value) == "false" { + return false, nil + } + return false, fmt.Errorf("Bad parameter") +} + +func getAuth(srv *Server, w http.ResponseWriter, r *http.Request, vars map[string]string) error { + b, err := json.Marshal(srv.registry.GetAuthConfig()) if err != nil { return err } @@ -63,18 +71,17 @@ func postAuth(srv *Server, w http.ResponseWriter, r *http.Request, vars map[stri return err } - if config.Username == srv.runtime.authConfig.Username { - config.Password = srv.runtime.authConfig.Password + if config.Username == srv.registry.GetAuthConfig().Username { + config.Password = srv.registry.GetAuthConfig().Password } newAuthConfig := auth.NewAuthConfig(config.Username, config.Password, config.Email, srv.runtime.root) status, err := auth.Login(newAuthConfig) if err != nil { return err - } else { - srv.runtime.graph.getHttpClient().Jar = cookiejar.NewCookieJar() - srv.runtime.authConfig = newAuthConfig } + srv.registry.ResetClient(newAuthConfig) + if status != "" { b, err := json.Marshal(&ApiAuth{Status: status}) if err != nil { @@ -116,7 +123,7 @@ func getContainersExport(srv *Server, w http.ResponseWriter, r *http.Request, va name := vars["name"] if err := srv.ContainerExport(name, w); err != nil { - Debugf("%s", err.Error()) + utils.Debugf("%s", err.Error()) return err } return nil @@ -127,7 +134,10 @@ func getImagesJson(srv *Server, w http.ResponseWriter, r *http.Request, vars map return err } - all := r.Form.Get("all") == "1" + all, err := getBoolParam(r.Form.Get("all")) + if err != nil { + return err + } filter := r.Form.Get("filter") outs, err := srv.Images(all, filter) @@ -197,7 +207,10 @@ func getContainersPs(srv *Server, w http.ResponseWriter, r *http.Request, vars m if err := parseForm(r); err != nil { return err } - all := r.Form.Get("all") == "1" + all, err := getBoolParam(r.Form.Get("all")) + if err != nil { + return err + } since := r.Form.Get("since") before := r.Form.Get("before") n, err := strconv.Atoi(r.Form.Get("limit")) @@ -224,7 +237,10 @@ func postImagesTag(srv *Server, w http.ResponseWriter, r *http.Request, vars map return fmt.Errorf("Missing parameter") } name := vars["name"] - force := r.Form.Get("force") == "1" + force, err := getBoolParam(r.Form.Get("force")) + if err != nil { + return err + } if err := srv.ContainerTag(name, repo, tag, force); err != nil { return err @@ -239,7 +255,7 @@ func postCommit(srv *Server, w http.ResponseWriter, r *http.Request, vars map[st } config := &Config{} if err := json.NewDecoder(r.Body).Decode(config); err != nil { - Debugf("%s", err.Error()) + utils.Debugf("%s", err.Error()) } repo := r.Form.Get("repo") tag := r.Form.Get("tag") @@ -335,7 +351,6 @@ func postImagesPush(srv *Server, w http.ResponseWriter, r *http.Request, vars ma if err := parseForm(r); err != nil { return err } - registry := r.Form.Get("registry") if vars == nil { @@ -363,7 +378,7 @@ func postBuild(srv *Server, w http.ResponseWriter, r *http.Request, vars map[str defer in.Close() fmt.Fprintf(out, "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.docker.raw-stream\r\n\r\n") if err := srv.ImageCreateFromFile(in, out); err != nil { - fmt.Fprintln(out, "Error: %s\n", err) + fmt.Fprintf(out, "Error: %s\n", err) } return nil } @@ -425,7 +440,10 @@ func deleteContainers(srv *Server, w http.ResponseWriter, r *http.Request, vars return fmt.Errorf("Missing parameter") } name := vars["name"] - removeVolume := r.Form.Get("v") == "1" + removeVolume, err := getBoolParam(r.Form.Get("v")) + if err != nil { + return err + } if err := srv.ContainerDestroy(name, removeVolume); err != nil { return err @@ -500,11 +518,27 @@ func postContainersAttach(srv *Server, w http.ResponseWriter, r *http.Request, v if err := parseForm(r); err != nil { return err } - logs := r.Form.Get("logs") == "1" - stream := r.Form.Get("stream") == "1" - stdin := r.Form.Get("stdin") == "1" - stdout := r.Form.Get("stdout") == "1" - stderr := r.Form.Get("stderr") == "1" + logs, err := getBoolParam(r.Form.Get("logs")) + if err != nil { + return err + } + stream, err := getBoolParam(r.Form.Get("stream")) + if err != nil { + return err + } + stdin, err := getBoolParam(r.Form.Get("stdin")) + if err != nil { + return err + } + stdout, err := getBoolParam(r.Form.Get("stdout")) + if err != nil { + return err + } + stderr, err := getBoolParam(r.Form.Get("stderr")) + if err != nil { + return err + } + if vars == nil { return fmt.Errorf("Missing parameter") } @@ -602,20 +636,20 @@ func ListenAndServe(addr string, srv *Server, logging bool) error { for method, routes := range m { for route, fct := range routes { - Debugf("Registering %s, %s", method, route) + utils.Debugf("Registering %s, %s", method, route) // NOTE: scope issue, make sure the variables are local and won't be changed localRoute := route localMethod := method localFct := fct r.Path(localRoute).Methods(localMethod).HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - Debugf("Calling %s %s", localMethod, localRoute) + utils.Debugf("Calling %s %s", localMethod, localRoute) if logging { log.Println(r.Method, r.RequestURI) } if strings.Contains(r.Header.Get("User-Agent"), "Docker-Client/") { userAgent := strings.Split(r.Header.Get("User-Agent"), "/") if len(userAgent) == 2 && userAgent[1] != VERSION { - Debugf("Warning: client and server don't have the same version (client: %s, server: %s)", userAgent[1], VERSION) + utils.Debugf("Warning: client and server don't have the same version (client: %s, server: %s)", userAgent[1], VERSION) } } if err := localFct(srv, w, r, mux.Vars(r)); err != nil { diff --git a/api_test.go b/api_test.go index 17075dae7f..a4a78d8996 100644 --- a/api_test.go +++ b/api_test.go @@ -6,6 +6,8 @@ import ( "bytes" "encoding/json" "github.com/dotcloud/docker/auth" + "github.com/dotcloud/docker/registry" + "github.com/dotcloud/docker/utils" "io" "net" "net/http" @@ -23,7 +25,10 @@ func TestGetAuth(t *testing.T) { } defer nuke(runtime) - srv := &Server{runtime: runtime} + srv := &Server{ + runtime: runtime, + registry: registry.NewRegistry(runtime.root), + } r := httptest.NewRecorder() @@ -46,13 +51,14 @@ func TestGetAuth(t *testing.T) { if err := postAuth(srv, r, req, nil); err != nil { t.Fatal(err) } + if r.Code != http.StatusOK && r.Code != 0 { t.Fatalf("%d OK or 0 expected, received %d\n", http.StatusOK, r.Code) } - if runtime.authConfig.Username != authConfig.Username || - runtime.authConfig.Password != authConfig.Password || - runtime.authConfig.Email != authConfig.Email { + newAuthConfig := srv.registry.GetAuthConfig() + if newAuthConfig.Username != authConfig.Username || + newAuthConfig.Email != authConfig.Email { t.Fatalf("The auth configuration hasn't been set correctly") } } @@ -143,7 +149,7 @@ func TestGetImagesJson(t *testing.T) { r2 := httptest.NewRecorder() // all=1 - req2, err := http.NewRequest("GET", "/images/json?all=1", nil) + req2, err := http.NewRequest("GET", "/images/json?all=true", nil) if err != nil { t.Fatal(err) } @@ -185,6 +191,24 @@ func TestGetImagesJson(t *testing.T) { if len(images3) != 0 { t.Errorf("Excepted 1 image, %d found", len(images3)) } + + r4 := httptest.NewRecorder() + + // all=foobar + req4, err := http.NewRequest("GET", "/images/json?all=foobar", nil) + if err != nil { + t.Fatal(err) + } + + err = getImagesJson(srv, r4, req4, nil) + if err == nil { + t.Fatalf("Error expected, received none") + } + + httpError(r4, err) + if r4.Code != http.StatusBadRequest { + t.Fatalf("%d Bad Request expected, received %d\n", http.StatusBadRequest, r4.Code) + } } func TestGetImagesViz(t *testing.T) { @@ -222,7 +246,10 @@ func TestGetImagesSearch(t *testing.T) { } defer nuke(runtime) - srv := &Server{runtime: runtime} + srv := &Server{ + runtime: runtime, + registry: registry.NewRegistry(runtime.root), + } r := httptest.NewRecorder() @@ -476,13 +503,16 @@ func TestPostAuth(t *testing.T) { } defer nuke(runtime) - srv := &Server{runtime: runtime} + srv := &Server{ + runtime: runtime, + registry: registry.NewRegistry(runtime.root), + } authConfigOrig := &auth.AuthConfig{ Username: "utest", Email: "utest@yopmail.com", } - runtime.authConfig = authConfigOrig + srv.registry.ResetClient(authConfigOrig) r := httptest.NewRecorder() if err := getAuth(srv, r, nil, nil); err != nil { @@ -811,7 +841,7 @@ func TestPostContainersCreate(t *testing.T) { if _, err := os.Stat(path.Join(container.rwPath(), "test")); err != nil { if os.IsNotExist(err) { - Debugf("Err: %s", err) + utils.Debugf("Err: %s", err) t.Fatalf("The test file has not been created") } t.Fatal(err) diff --git a/auth/auth.go b/auth/auth.go index 5a5987ace8..2b99c95038 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -15,13 +15,13 @@ import ( const CONFIGFILE = ".dockercfg" // the registry server we want to login against -const INDEX_SERVER = "https://index.docker.io" +const INDEX_SERVER = "https://index.docker.io/v1" type AuthConfig struct { Username string `json:"username"` Password string `json:"password"` Email string `json:"email"` - rootPath string `json:-` + rootPath string } func NewAuthConfig(username, password, email, rootPath string) *AuthConfig { @@ -33,6 +33,13 @@ func NewAuthConfig(username, password, email, rootPath string) *AuthConfig { } } +func IndexServerAddress() string { + if os.Getenv("DOCKER_INDEX_URL") != "" { + return os.Getenv("DOCKER_INDEX_URL") + "/v1" + } + return INDEX_SERVER +} + // create a base64 encoded auth string to store in config func EncodeAuth(authConfig *AuthConfig) string { authStr := authConfig.Username + ":" + authConfig.Password @@ -119,7 +126,7 @@ func Login(authConfig *AuthConfig) (string, error) { // using `bytes.NewReader(jsonBody)` here causes the server to respond with a 411 status. b := strings.NewReader(string(jsonBody)) - req1, err := http.Post(INDEX_SERVER+"/v1/users/", "application/json; charset=utf-8", b) + req1, err := http.Post(IndexServerAddress()+"/users/", "application/json; charset=utf-8", b) if err != nil { return "", fmt.Errorf("Server Error: %s", err) } @@ -139,7 +146,7 @@ func Login(authConfig *AuthConfig) (string, error) { "Please check your e-mail for a confirmation link.") } else if reqStatusCode == 400 { if string(reqBody) == "\"Username or email already exists\"" { - req, err := http.NewRequest("GET", INDEX_SERVER+"/v1/users/", nil) + req, err := http.NewRequest("GET", IndexServerAddress()+"/users/", nil) req.SetBasicAuth(authConfig.Username, authConfig.Password) resp, err := client.Do(req) if err != nil { diff --git a/auth/auth_test.go b/auth/auth_test.go index ca584f9314..6c8d032cf7 100644 --- a/auth/auth_test.go +++ b/auth/auth_test.go @@ -1,6 +1,10 @@ package auth import ( + "crypto/rand" + "encoding/hex" + "os" + "strings" "testing" ) @@ -21,3 +25,49 @@ func TestEncodeAuth(t *testing.T) { t.Fatal("AuthString encoding isn't correct.") } } + +func TestLogin(t *testing.T) { + os.Setenv("DOCKER_INDEX_URL", "https://indexstaging-docker.dotcloud.com") + defer os.Setenv("DOCKER_INDEX_URL", "") + authConfig := NewAuthConfig("unittester", "surlautrerivejetattendrai", "noise+unittester@dotcloud.com", "/tmp") + status, err := Login(authConfig) + if err != nil { + t.Fatal(err) + } + if status != "Login Succeeded\n" { + t.Fatalf("Expected status \"Login Succeeded\", found \"%s\" instead", status) + } +} + +func TestCreateAccount(t *testing.T) { + os.Setenv("DOCKER_INDEX_URL", "https://indexstaging-docker.dotcloud.com") + defer os.Setenv("DOCKER_INDEX_URL", "") + tokenBuffer := make([]byte, 16) + _, err := rand.Read(tokenBuffer) + if err != nil { + t.Fatal(err) + } + token := hex.EncodeToString(tokenBuffer)[:12] + username := "ut" + token + authConfig := NewAuthConfig(username, "test42", "docker-ut+"+token+"@example.com", "/tmp") + status, err := Login(authConfig) + if err != nil { + t.Fatal(err) + } + expectedStatus := "Account created. Please use the confirmation link we sent" + + " to your e-mail to activate it.\n" + if status != expectedStatus { + t.Fatalf("Expected status: \"%s\", found \"%s\" instead.", expectedStatus, status) + } + + status, err = Login(authConfig) + if err == nil { + t.Fatalf("Expected error but found nil instead") + } + + expectedError := "Login: Account is not Active" + + if !strings.Contains(err.Error(), expectedError) { + t.Fatalf("Expected message \"%s\" but found \"%s\" instead", expectedError, err.Error()) + } +} diff --git a/buildbot/README.rst b/buildbot/README.rst deleted file mode 100644 index a52b9769ef..0000000000 --- a/buildbot/README.rst +++ /dev/null @@ -1,20 +0,0 @@ -Buildbot -======== - -Buildbot is a continuous integration system designed to automate the -build/test cycle. By automatically rebuilding and testing the tree each time -something has changed, build problems are pinpointed quickly, before other -developers are inconvenienced by the failure. - -When running 'make hack' at the docker root directory, it spawns a virtual -machine in the background running a buildbot instance and adds a git -post-commit hook that automatically run docker tests for you. - -You can check your buildbot instance at http://192.168.33.21:8010/waterfall - - -Buildbot dependencies ---------------------- - -vagrant, virtualbox packages and python package requests - diff --git a/buildbot/Vagrantfile b/buildbot/Vagrantfile deleted file mode 100644 index ea027f0666..0000000000 --- a/buildbot/Vagrantfile +++ /dev/null @@ -1,28 +0,0 @@ -# -*- mode: ruby -*- -# vi: set ft=ruby : - -$BUILDBOT_IP = '192.168.33.21' - -def v10(config) - config.vm.box = "quantal64_3.5.0-25" - config.vm.box_url = "http://get.docker.io/vbox/ubuntu/12.10/quantal64_3.5.0-25.box" - config.vm.share_folder 'v-data', '/data/docker', File.dirname(__FILE__) + '/..' - config.vm.network :hostonly, $BUILDBOT_IP - - # Ensure puppet is installed on the instance - config.vm.provision :shell, :inline => 'apt-get -qq update; apt-get install -y puppet' - - config.vm.provision :puppet do |puppet| - puppet.manifests_path = '.' - puppet.manifest_file = 'buildbot.pp' - puppet.options = ['--templatedir','.'] - end -end - -Vagrant::VERSION < '1.1.0' and Vagrant::Config.run do |config| - v10(config) -end - -Vagrant::VERSION >= '1.1.0' and Vagrant.configure('1') do |config| - v10(config) -end diff --git a/buildbot/buildbot-cfg/buildbot-cfg.sh b/buildbot/buildbot-cfg/buildbot-cfg.sh deleted file mode 100755 index 5e4e7432fd..0000000000 --- a/buildbot/buildbot-cfg/buildbot-cfg.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash - -# Auto setup of buildbot configuration. Package installation is being done -# on buildbot.pp -# Dependencies: buildbot, buildbot-slave, supervisor - -SLAVE_NAME='buildworker' -SLAVE_SOCKET='localhost:9989' -BUILDBOT_PWD='pass-docker' -USER='vagrant' -ROOT_PATH='/data/buildbot' -DOCKER_PATH='/data/docker' -BUILDBOT_CFG="$DOCKER_PATH/buildbot/buildbot-cfg" -IP=$(grep BUILDBOT_IP /data/docker/buildbot/Vagrantfile | awk -F "'" '{ print $2; }') - -function run { su $USER -c "$1"; } - -export PATH=/bin:sbin:/usr/bin:/usr/sbin:/usr/local/bin - -# Exit if buildbot has already been installed -[ -d "$ROOT_PATH" ] && exit 0 - -# Setup buildbot -run "mkdir -p ${ROOT_PATH}" -cd ${ROOT_PATH} -run "buildbot create-master master" -run "cp $BUILDBOT_CFG/master.cfg master" -run "sed -i 's/localhost/$IP/' master/master.cfg" -run "buildslave create-slave slave $SLAVE_SOCKET $SLAVE_NAME $BUILDBOT_PWD" - -# Allow buildbot subprocesses (docker tests) to properly run in containers, -# in particular with docker -u -run "sed -i 's/^umask = None/umask = 000/' ${ROOT_PATH}/slave/buildbot.tac" - -# Setup supervisor -cp $BUILDBOT_CFG/buildbot.conf /etc/supervisor/conf.d/buildbot.conf -sed -i "s/^chmod=0700.*0700./chmod=0770\nchown=root:$USER/" /etc/supervisor/supervisord.conf -kill -HUP `pgrep -f "/usr/bin/python /usr/bin/supervisord"` - -# Add git hook -cp $BUILDBOT_CFG/post-commit $DOCKER_PATH/.git/hooks -sed -i "s/localhost/$IP/" $DOCKER_PATH/.git/hooks/post-commit - diff --git a/buildbot/buildbot.pp b/buildbot/buildbot.pp deleted file mode 100644 index 8109cdc2a0..0000000000 --- a/buildbot/buildbot.pp +++ /dev/null @@ -1,32 +0,0 @@ -node default { - $USER = 'vagrant' - $ROOT_PATH = '/data/buildbot' - $DOCKER_PATH = '/data/docker' - - exec {'apt_update': command => '/usr/bin/apt-get update' } - Package { require => Exec['apt_update'] } - group {'puppet': ensure => 'present'} - - # Install dependencies - Package { ensure => 'installed' } - package { ['python-dev','python-pip','supervisor','lxc','bsdtar','git','golang']: } - - file{[ '/data' ]: - owner => $USER, group => $USER, ensure => 'directory' } - - file {'/var/tmp/requirements.txt': - content => template('requirements.txt') } - - exec {'requirements': - require => [ Package['python-dev'], Package['python-pip'], - File['/var/tmp/requirements.txt'] ], - cwd => '/var/tmp', - command => "/bin/sh -c '(/usr/bin/pip install -r requirements.txt; - rm /var/tmp/requirements.txt)'" } - - exec {'buildbot-cfg-sh': - require => [ Package['supervisor'], Exec['requirements']], - path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin', - cwd => '/data', - command => "$DOCKER_PATH/buildbot/buildbot-cfg/buildbot-cfg.sh" } -} diff --git a/builder.go b/builder.go index 5c51d62b9e..1497644779 100644 --- a/builder.go +++ b/builder.go @@ -4,6 +4,7 @@ import ( "bufio" "encoding/json" "fmt" + "github.com/dotcloud/docker/utils" "io" "os" "path" @@ -45,7 +46,7 @@ func (builder *Builder) mergeConfig(userConf, imageConf *Config) { userConf.PortSpecs = imageConf.PortSpecs } if !userConf.Tty { - userConf.Tty = userConf.Tty + userConf.Tty = imageConf.Tty } if !userConf.OpenStdin { userConf.OpenStdin = imageConf.OpenStdin @@ -161,11 +162,11 @@ func (builder *Builder) clearTmp(containers, images map[string]struct{}) { for c := range containers { tmp := builder.runtime.Get(c) builder.runtime.Destroy(tmp) - Debugf("Removing container %s", c) + utils.Debugf("Removing container %s", c) } for i := range images { builder.runtime.graph.Delete(i) - Debugf("Removing image %s", i) + utils.Debugf("Removing image %s", i) } } @@ -234,28 +235,29 @@ func (builder *Builder) Build(dockerfile io.Reader, stdout io.Writer) (*Image, e fmt.Fprintf(stdout, "FROM %s\n", arguments) image, err = builder.runtime.repositories.LookupImage(arguments) if err != nil { - if builder.runtime.graph.IsNotExist(err) { + // if builder.runtime.graph.IsNotExist(err) { - var tag, remote string - if strings.Contains(arguments, ":") { - remoteParts := strings.Split(arguments, ":") - tag = remoteParts[1] - remote = remoteParts[0] - } else { - remote = arguments - } + // var tag, remote string + // if strings.Contains(arguments, ":") { + // remoteParts := strings.Split(arguments, ":") + // tag = remoteParts[1] + // remote = remoteParts[0] + // } else { + // remote = arguments + // } - if err := builder.runtime.graph.PullRepository(stdout, remote, tag, builder.runtime.repositories, builder.runtime.authConfig); err != nil { - return nil, err - } + // panic("TODO: reimplement this") + // // if err := builder.runtime.graph.PullRepository(stdout, remote, tag, builder.runtime.repositories, builder.runtime.authConfig); err != nil { + // // return nil, err + // // } - image, err = builder.runtime.repositories.LookupImage(arguments) - if err != nil { - return nil, err - } - } else { - return nil, err - } + // image, err = builder.runtime.repositories.LookupImage(arguments) + // if err != nil { + // return nil, err + // } + // } else { + return nil, err + // } } config = &Config{} @@ -286,7 +288,7 @@ func (builder *Builder) Build(dockerfile io.Reader, stdout io.Writer) (*Image, e break } - Debugf("Env -----> %v ------ %v\n", config.Env, env) + utils.Debugf("Env -----> %v ------ %v\n", config.Env, env) // Create the container and start it c, err := builder.Create(config) @@ -410,7 +412,7 @@ func (builder *Builder) Build(dockerfile io.Reader, stdout io.Writer) (*Image, e destPath := strings.Trim(tmp[1], " ") fmt.Fprintf(stdout, "COPY %s to %s in %s\n", sourceUrl, destPath, base.ShortId()) - file, err := Download(sourceUrl, stdout) + file, err := utils.Download(sourceUrl, stdout) if err != nil { return nil, err } diff --git a/builder_test.go b/builder_test.go index 08b7dd58cc..e3a24e86ec 100644 --- a/builder_test.go +++ b/builder_test.go @@ -1,6 +1,7 @@ package docker import ( + "github.com/dotcloud/docker/utils" "strings" "testing" ) @@ -24,7 +25,7 @@ func TestBuild(t *testing.T) { builder := NewBuilder(runtime) - img, err := builder.Build(strings.NewReader(Dockerfile), &nopWriter{}) + img, err := builder.Build(strings.NewReader(Dockerfile), &utils.NopWriter{}) if err != nil { t.Fatal(err) } diff --git a/commands.go b/commands.go index 9e26790f5d..8734da176f 100644 --- a/commands.go +++ b/commands.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/dotcloud/docker/auth" "github.com/dotcloud/docker/term" + "github.com/dotcloud/docker/utils" "io" "io/ioutil" "net" @@ -15,6 +16,7 @@ import ( "net/url" "os" "path/filepath" + "reflect" "strconv" "strings" "text/tabwriter" @@ -29,50 +31,28 @@ var ( ) func ParseCommands(args ...string) error { - - cmds := map[string]func(args ...string) error{ - "attach": CmdAttach, - "build": CmdBuild, - "commit": CmdCommit, - "diff": CmdDiff, - "export": CmdExport, - "images": CmdImages, - "info": CmdInfo, - "insert": CmdInsert, - "inspect": CmdInspect, - "import": CmdImport, - "history": CmdHistory, - "kill": CmdKill, - "login": CmdLogin, - "logs": CmdLogs, - "port": CmdPort, - "ps": CmdPs, - "pull": CmdPull, - "push": CmdPush, - "restart": CmdRestart, - "rm": CmdRm, - "rmi": CmdRmi, - "run": CmdRun, - "tag": CmdTag, - "search": CmdSearch, - "start": CmdStart, - "stop": CmdStop, - "version": CmdVersion, - "wait": CmdWait, - } + cli := NewDockerCli("0.0.0.0", 4243) if len(args) > 0 { - cmd, exists := cmds[args[0]] + methodName := "Cmd" + strings.ToUpper(args[0][:1]) + strings.ToLower(args[0][1:]) + method, exists := reflect.TypeOf(cli).MethodByName(methodName) if !exists { fmt.Println("Error: Command not found:", args[0]) - return cmdHelp(args...) + return cli.CmdHelp(args...) } - return cmd(args[1:]...) + ret := method.Func.CallSlice([]reflect.Value{ + reflect.ValueOf(cli), + reflect.ValueOf(args[1:]), + })[0].Interface() + if ret == nil { + return nil + } + return ret.(error) } - return cmdHelp(args...) + return cli.CmdHelp(args...) } -func cmdHelp(args ...string) error { +func (cli *DockerCli) CmdHelp(args ...string) error { help := "Usage: docker COMMAND [arg...]\n\nA self-sufficient runtime for linux containers.\n\nCommands:\n" for _, cmd := range [][]string{ {"attach", "Attach to a running container"}, @@ -110,7 +90,7 @@ func cmdHelp(args ...string) error { return nil } -func CmdInsert(args ...string) error { +func (cli *DockerCli) CmdInsert(args ...string) error { cmd := Subcmd("insert", "IMAGE URL PATH", "Insert a file from URL in the IMAGE at PATH") if err := cmd.Parse(args); err != nil { return nil @@ -124,20 +104,20 @@ func CmdInsert(args ...string) error { v.Set("url", cmd.Arg(1)) v.Set("path", cmd.Arg(2)) - err := hijack("POST", "/images/"+cmd.Arg(0)+"?"+v.Encode(), false) + err := cli.hijack("POST", "/images/"+cmd.Arg(0)+"?"+v.Encode(), false) if err != nil { return err } return nil } -func CmdBuild(args ...string) error { +func (cli *DockerCli) CmdBuild(args ...string) error { cmd := Subcmd("build", "-", "Build an image from Dockerfile via stdin") if err := cmd.Parse(args); err != nil { return nil } - err := hijack("POST", "/build", false) + err := cli.hijack("POST", "/build", false) if err != nil { return err } @@ -145,7 +125,7 @@ func CmdBuild(args ...string) error { } // 'docker login': login / register a user to registry service. -func CmdLogin(args ...string) error { +func (cli *DockerCli) CmdLogin(args ...string) error { var readStringOnRawTerminal = func(stdin io.Reader, stdout io.Writer, echo bool) string { char := make([]byte, 1) buffer := make([]byte, 64) @@ -188,11 +168,11 @@ func CmdLogin(args ...string) error { return readStringOnRawTerminal(stdin, stdout, false) } - oldState, err := SetRawTerminal() + oldState, err := term.SetRawTerminal() if err != nil { return err } else { - defer RestoreTerminal(oldState) + defer term.RestoreTerminal(oldState) } cmd := Subcmd("login", "", "Register or Login to the docker registry server") @@ -200,7 +180,7 @@ func CmdLogin(args ...string) error { return nil } - body, _, err := call("GET", "/auth", nil) + body, _, err := cli.call("GET", "/auth", nil) if err != nil { return err } @@ -241,7 +221,7 @@ func CmdLogin(args ...string) error { out.Password = password out.Email = email - body, _, err = call("POST", "/auth", out) + body, _, err = cli.call("POST", "/auth", out) if err != nil { return err } @@ -252,14 +232,14 @@ func CmdLogin(args ...string) error { return err } if out2.Status != "" { - RestoreTerminal(oldState) + term.RestoreTerminal(oldState) fmt.Print(out2.Status) } return nil } // 'docker wait': block until a container stops -func CmdWait(args ...string) error { +func (cli *DockerCli) CmdWait(args ...string) error { cmd := Subcmd("wait", "CONTAINER [CONTAINER...]", "Block until a container stops, then print its exit code.") if err := cmd.Parse(args); err != nil { return nil @@ -269,7 +249,7 @@ func CmdWait(args ...string) error { return nil } for _, name := range cmd.Args() { - body, _, err := call("POST", "/containers/"+name+"/wait", nil) + body, _, err := cli.call("POST", "/containers/"+name+"/wait", nil) if err != nil { fmt.Printf("%s", err) } else { @@ -285,17 +265,20 @@ func CmdWait(args ...string) error { } // 'docker version': show version information -func CmdVersion(args ...string) error { +func (cli *DockerCli) CmdVersion(args ...string) error { cmd := Subcmd("version", "", "Show the docker version information.") + fmt.Println(len(args)) if err := cmd.Parse(args); err != nil { return nil } + + fmt.Println(cmd.NArg()) if cmd.NArg() > 0 { cmd.Usage() return nil } - body, _, err := call("GET", "/version", nil) + body, _, err := cli.call("GET", "/version", nil) if err != nil { return err } @@ -303,7 +286,7 @@ func CmdVersion(args ...string) error { var out ApiVersion err = json.Unmarshal(body, &out) if err != nil { - Debugf("Error unmarshal: body: %s, err: %s\n", body, err) + utils.Debugf("Error unmarshal: body: %s, err: %s\n", body, err) return err } fmt.Println("Version:", out.Version) @@ -319,7 +302,7 @@ func CmdVersion(args ...string) error { } // 'docker info': display system-wide information. -func CmdInfo(args ...string) error { +func (cli *DockerCli) CmdInfo(args ...string) error { cmd := Subcmd("info", "", "Display system-wide information") if err := cmd.Parse(args); err != nil { return nil @@ -329,7 +312,7 @@ func CmdInfo(args ...string) error { return nil } - body, _, err := call("GET", "/info", nil) + body, _, err := cli.call("GET", "/info", nil) if err != nil { return err } @@ -347,7 +330,7 @@ func CmdInfo(args ...string) error { return nil } -func CmdStop(args ...string) error { +func (cli *DockerCli) CmdStop(args ...string) error { cmd := Subcmd("stop", "[OPTIONS] CONTAINER [CONTAINER...]", "Stop a running container") nSeconds := cmd.Int("t", 10, "wait t seconds before killing the container") if err := cmd.Parse(args); err != nil { @@ -362,7 +345,7 @@ func CmdStop(args ...string) error { v.Set("t", strconv.Itoa(*nSeconds)) for _, name := range cmd.Args() { - _, _, err := call("POST", "/containers/"+name+"/stop?"+v.Encode(), nil) + _, _, err := cli.call("POST", "/containers/"+name+"/stop?"+v.Encode(), nil) if err != nil { fmt.Printf("%s", err) } else { @@ -372,7 +355,7 @@ func CmdStop(args ...string) error { return nil } -func CmdRestart(args ...string) error { +func (cli *DockerCli) CmdRestart(args ...string) error { cmd := Subcmd("restart", "[OPTIONS] CONTAINER [CONTAINER...]", "Restart a running container") nSeconds := cmd.Int("t", 10, "wait t seconds before killing the container") if err := cmd.Parse(args); err != nil { @@ -387,7 +370,7 @@ func CmdRestart(args ...string) error { v.Set("t", strconv.Itoa(*nSeconds)) for _, name := range cmd.Args() { - _, _, err := call("POST", "/containers/"+name+"/restart?"+v.Encode(), nil) + _, _, err := cli.call("POST", "/containers/"+name+"/restart?"+v.Encode(), nil) if err != nil { fmt.Printf("%s", err) } else { @@ -397,7 +380,7 @@ func CmdRestart(args ...string) error { return nil } -func CmdStart(args ...string) error { +func (cli *DockerCli) CmdStart(args ...string) error { cmd := Subcmd("start", "CONTAINER [CONTAINER...]", "Restart a stopped container") if err := cmd.Parse(args); err != nil { return nil @@ -408,7 +391,7 @@ func CmdStart(args ...string) error { } for _, name := range args { - _, _, err := call("POST", "/containers/"+name+"/start", nil) + _, _, err := cli.call("POST", "/containers/"+name+"/start", nil) if err != nil { fmt.Printf("%s", err) } else { @@ -418,7 +401,7 @@ func CmdStart(args ...string) error { return nil } -func CmdInspect(args ...string) error { +func (cli *DockerCli) CmdInspect(args ...string) error { cmd := Subcmd("inspect", "CONTAINER|IMAGE", "Return low-level information on a container/image") if err := cmd.Parse(args); err != nil { return nil @@ -427,9 +410,9 @@ func CmdInspect(args ...string) error { cmd.Usage() return nil } - obj, _, err := call("GET", "/containers/"+cmd.Arg(0)+"/json", nil) + obj, _, err := cli.call("GET", "/containers/"+cmd.Arg(0)+"/json", nil) if err != nil { - obj, _, err = call("GET", "/images/"+cmd.Arg(0)+"/json", nil) + obj, _, err = cli.call("GET", "/images/"+cmd.Arg(0)+"/json", nil) if err != nil { return err } @@ -445,7 +428,7 @@ func CmdInspect(args ...string) error { return nil } -func CmdPort(args ...string) error { +func (cli *DockerCli) CmdPort(args ...string) error { cmd := Subcmd("port", "CONTAINER PRIVATE_PORT", "Lookup the public-facing port which is NAT-ed to PRIVATE_PORT") if err := cmd.Parse(args); err != nil { return nil @@ -455,7 +438,7 @@ func CmdPort(args ...string) error { return nil } - body, _, err := call("GET", "/containers/"+cmd.Arg(0)+"/json", nil) + body, _, err := cli.call("GET", "/containers/"+cmd.Arg(0)+"/json", nil) if err != nil { return err } @@ -474,7 +457,7 @@ func CmdPort(args ...string) error { } // 'docker rmi IMAGE' removes all images with the name IMAGE -func CmdRmi(args ...string) error { +func (cli *DockerCli) CmdRmi(args ...string) error { cmd := Subcmd("rmi", "IMAGE [IMAGE...]", "Remove an image") if err := cmd.Parse(args); err != nil { return nil @@ -485,7 +468,7 @@ func CmdRmi(args ...string) error { } for _, name := range cmd.Args() { - _, _, err := call("DELETE", "/images/"+name, nil) + _, _, err := cli.call("DELETE", "/images/"+name, nil) if err != nil { fmt.Printf("%s", err) } else { @@ -495,7 +478,7 @@ func CmdRmi(args ...string) error { return nil } -func CmdHistory(args ...string) error { +func (cli *DockerCli) CmdHistory(args ...string) error { cmd := Subcmd("history", "IMAGE", "Show the history of an image") if err := cmd.Parse(args); err != nil { return nil @@ -505,7 +488,7 @@ func CmdHistory(args ...string) error { return nil } - body, _, err := call("GET", "/images/"+cmd.Arg(0)+"/history", nil) + body, _, err := cli.call("GET", "/images/"+cmd.Arg(0)+"/history", nil) if err != nil { return err } @@ -519,13 +502,13 @@ func CmdHistory(args ...string) error { fmt.Fprintln(w, "ID\tCREATED\tCREATED BY") for _, out := range outs { - fmt.Fprintf(w, "%s\t%s ago\t%s\n", out.Id, HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.CreatedBy) + fmt.Fprintf(w, "%s\t%s ago\t%s\n", out.Id, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.CreatedBy) } w.Flush() return nil } -func CmdRm(args ...string) error { +func (cli *DockerCli) CmdRm(args ...string) error { cmd := Subcmd("rm", "[OPTIONS] CONTAINER [CONTAINER...]", "Remove a container") v := cmd.Bool("v", false, "Remove the volumes associated to the container") if err := cmd.Parse(args); err != nil { @@ -540,7 +523,7 @@ func CmdRm(args ...string) error { val.Set("v", "1") } for _, name := range cmd.Args() { - _, _, err := call("DELETE", "/containers/"+name+"?"+val.Encode(), nil) + _, _, err := cli.call("DELETE", "/containers/"+name+"?"+val.Encode(), nil) if err != nil { fmt.Printf("%s", err) } else { @@ -551,7 +534,7 @@ func CmdRm(args ...string) error { } // 'docker kill NAME' kills a running container -func CmdKill(args ...string) error { +func (cli *DockerCli) CmdKill(args ...string) error { cmd := Subcmd("kill", "CONTAINER [CONTAINER...]", "Kill a running container") if err := cmd.Parse(args); err != nil { return nil @@ -562,7 +545,7 @@ func CmdKill(args ...string) error { } for _, name := range args { - _, _, err := call("POST", "/containers/"+name+"/kill", nil) + _, _, err := cli.call("POST", "/containers/"+name+"/kill", nil) if err != nil { fmt.Printf("%s", err) } else { @@ -572,7 +555,7 @@ func CmdKill(args ...string) error { return nil } -func CmdImport(args ...string) error { +func (cli *DockerCli) CmdImport(args ...string) error { cmd := Subcmd("import", "URL|- [REPOSITORY [TAG]]", "Create a new filesystem image from the contents of a tarball") if err := cmd.Parse(args); err != nil { @@ -588,14 +571,14 @@ func CmdImport(args ...string) error { v.Set("tag", tag) v.Set("fromSrc", src) - err := hijack("POST", "/images/create?"+v.Encode(), false) + err := cli.hijack("POST", "/images/create?"+v.Encode(), false) if err != nil { return err } return nil } -func CmdPush(args ...string) error { +func (cli *DockerCli) CmdPush(args ...string) error { cmd := Subcmd("push", "[OPTION] NAME", "Push an image or a repository to the registry") registry := cmd.String("registry", "", "Registry host to push the image to") if err := cmd.Parse(args); err != nil { @@ -608,7 +591,7 @@ func CmdPush(args ...string) error { return nil } - body, _, err := call("GET", "/auth", nil) + body, _, err := cli.call("GET", "/auth", nil) if err != nil { return err } @@ -621,11 +604,11 @@ func CmdPush(args ...string) error { // If the login failed AND we're using the index, abort if *registry == "" && out.Username == "" { - if err := CmdLogin(args...); err != nil { + if err := cli.CmdLogin(args...); err != nil { return err } - body, _, err = call("GET", "/auth", nil) + body, _, err = cli.call("GET", "/auth", nil) if err != nil { return err } @@ -645,13 +628,13 @@ func CmdPush(args ...string) error { v := url.Values{} v.Set("registry", *registry) - if err := hijack("POST", "/images/"+name+"/push?"+v.Encode(), false); err != nil { + if err := cli.hijack("POST", "/images/"+name+"/push?"+v.Encode(), false); err != nil { return err } return nil } -func CmdPull(args ...string) error { +func (cli *DockerCli) CmdPull(args ...string) error { cmd := Subcmd("pull", "NAME", "Pull an image or a repository from the registry") tag := cmd.String("t", "", "Download tagged image in repository") registry := cmd.String("registry", "", "Registry to download from. Necessary if image is pulled by ID") @@ -676,14 +659,14 @@ func CmdPull(args ...string) error { v.Set("tag", *tag) v.Set("registry", *registry) - if err := hijack("POST", "/images/create?"+v.Encode(), false); err != nil { + if err := cli.hijack("POST", "/images/create?"+v.Encode(), false); err != nil { return err } return nil } -func CmdImages(args ...string) error { +func (cli *DockerCli) CmdImages(args ...string) error { cmd := Subcmd("images", "[OPTIONS] [NAME]", "List images") quiet := cmd.Bool("q", false, "only show numeric IDs") all := cmd.Bool("a", false, "show all images") @@ -699,7 +682,7 @@ func CmdImages(args ...string) error { } if *flViz { - body, _, err := call("GET", "/images/viz", false) + body, _, err := cli.call("GET", "/images/viz", false) if err != nil { return err } @@ -713,7 +696,7 @@ func CmdImages(args ...string) error { v.Set("all", "1") } - body, _, err := call("GET", "/images/json?"+v.Encode(), nil) + body, _, err := cli.call("GET", "/images/json?"+v.Encode(), nil) if err != nil { return err } @@ -742,14 +725,14 @@ func CmdImages(args ...string) error { if *noTrunc { fmt.Fprintf(w, "%s\t", out.Id) } else { - fmt.Fprintf(w, "%s\t", TruncateId(out.Id)) + fmt.Fprintf(w, "%s\t", utils.TruncateId(out.Id)) } - fmt.Fprintf(w, "%s ago\n", HumanDuration(time.Now().Sub(time.Unix(out.Created, 0)))) + fmt.Fprintf(w, "%s ago\n", utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0)))) } else { if *noTrunc { fmt.Fprintln(w, out.Id) } else { - fmt.Fprintln(w, TruncateId(out.Id)) + fmt.Fprintln(w, utils.TruncateId(out.Id)) } } } @@ -761,7 +744,7 @@ func CmdImages(args ...string) error { return nil } -func CmdPs(args ...string) error { +func (cli *DockerCli) CmdPs(args ...string) error { cmd := Subcmd("ps", "[OPTIONS]", "List containers") quiet := cmd.Bool("q", false, "Only display numeric IDs") all := cmd.Bool("a", false, "Show all containers. Only running containers are shown by default.") @@ -791,7 +774,7 @@ func CmdPs(args ...string) error { v.Set("before", *before) } - body, _, err := call("GET", "/containers/ps?"+v.Encode(), nil) + body, _, err := cli.call("GET", "/containers/ps?"+v.Encode(), nil) if err != nil { return err } @@ -809,15 +792,15 @@ func CmdPs(args ...string) error { for _, out := range outs { if !*quiet { if *noTrunc { - fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s ago\t%s\n", out.Id, out.Image, out.Command, out.Status, HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Ports) + fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s ago\t%s\n", out.Id, out.Image, out.Command, out.Status, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Ports) } else { - fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s ago\t%s\n", TruncateId(out.Id), out.Image, Trunc(out.Command, 20), out.Status, HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Ports) + fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s ago\t%s\n", utils.TruncateId(out.Id), out.Image, utils.Trunc(out.Command, 20), out.Status, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Ports) } } else { if *noTrunc { fmt.Fprintln(w, out.Id) } else { - fmt.Fprintln(w, TruncateId(out.Id)) + fmt.Fprintln(w, utils.TruncateId(out.Id)) } } } @@ -828,7 +811,7 @@ func CmdPs(args ...string) error { return nil } -func CmdCommit(args ...string) error { +func (cli *DockerCli) CmdCommit(args ...string) error { cmd := Subcmd("commit", "[OPTIONS] CONTAINER [REPOSITORY [TAG]]", "Create a new image from a container's changes") flComment := cmd.String("m", "", "Commit message") flAuthor := cmd.String("author", "", "Author (eg. \"John Hannibal Smith \"") @@ -855,7 +838,7 @@ func CmdCommit(args ...string) error { return err } } - body, _, err := call("POST", "/commit?"+v.Encode(), config) + body, _, err := cli.call("POST", "/commit?"+v.Encode(), config) if err != nil { return err } @@ -870,7 +853,7 @@ func CmdCommit(args ...string) error { return nil } -func CmdExport(args ...string) error { +func (cli *DockerCli) CmdExport(args ...string) error { cmd := Subcmd("export", "CONTAINER", "Export the contents of a filesystem as a tar archive") if err := cmd.Parse(args); err != nil { return nil @@ -881,13 +864,13 @@ func CmdExport(args ...string) error { return nil } - if err := stream("GET", "/containers/"+cmd.Arg(0)+"/export"); err != nil { + if err := cli.stream("GET", "/containers/"+cmd.Arg(0)+"/export"); err != nil { return err } return nil } -func CmdDiff(args ...string) error { +func (cli *DockerCli) CmdDiff(args ...string) error { cmd := Subcmd("diff", "CONTAINER", "Inspect changes on a container's filesystem") if err := cmd.Parse(args); err != nil { return nil @@ -897,7 +880,7 @@ func CmdDiff(args ...string) error { return nil } - body, _, err := call("GET", "/containers/"+cmd.Arg(0)+"/changes", nil) + body, _, err := cli.call("GET", "/containers/"+cmd.Arg(0)+"/changes", nil) if err != nil { return err } @@ -913,7 +896,7 @@ func CmdDiff(args ...string) error { return nil } -func CmdLogs(args ...string) error { +func (cli *DockerCli) CmdLogs(args ...string) error { cmd := Subcmd("logs", "CONTAINER", "Fetch the logs of a container") if err := cmd.Parse(args); err != nil { return nil @@ -928,13 +911,13 @@ func CmdLogs(args ...string) error { v.Set("stdout", "1") v.Set("stderr", "1") - if err := 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); err != nil { return err } return nil } -func CmdAttach(args ...string) error { +func (cli *DockerCli) CmdAttach(args ...string) error { cmd := Subcmd("attach", "CONTAINER", "Attach to a running container") if err := cmd.Parse(args); err != nil { return nil @@ -944,7 +927,7 @@ func CmdAttach(args ...string) error { return nil } - body, _, err := call("GET", "/containers/"+cmd.Arg(0)+"/json", nil) + body, _, err := cli.call("GET", "/containers/"+cmd.Arg(0)+"/json", nil) if err != nil { return err } @@ -961,13 +944,13 @@ func CmdAttach(args ...string) error { v.Set("stderr", "1") v.Set("stdin", "1") - if err := hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), container.Config.Tty); err != nil { + if err := cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), container.Config.Tty); err != nil { return err } return nil } -func CmdSearch(args ...string) error { +func (cli *DockerCli) CmdSearch(args ...string) error { cmd := Subcmd("search", "NAME", "Search the docker index for images") if err := cmd.Parse(args); err != nil { return nil @@ -979,7 +962,7 @@ func CmdSearch(args ...string) error { v := url.Values{} v.Set("term", cmd.Arg(0)) - body, _, err := call("GET", "/images/search?"+v.Encode(), nil) + body, _, err := cli.call("GET", "/images/search?"+v.Encode(), nil) if err != nil { return err } @@ -1060,7 +1043,7 @@ func (opts PathOpts) Set(val string) error { return nil } -func CmdTag(args ...string) error { +func (cli *DockerCli) CmdTag(args ...string) error { cmd := Subcmd("tag", "[OPTIONS] IMAGE REPOSITORY [TAG]", "Tag an image into a repository") force := cmd.Bool("f", false, "Force") if err := cmd.Parse(args); err != nil { @@ -1081,13 +1064,13 @@ func CmdTag(args ...string) error { v.Set("force", "1") } - if _, _, err := call("POST", "/images/"+cmd.Arg(0)+"/tag?"+v.Encode(), nil); err != nil { + if _, _, err := cli.call("POST", "/images/"+cmd.Arg(0)+"/tag?"+v.Encode(), nil); err != nil { return err } return nil } -func CmdRun(args ...string) error { +func (cli *DockerCli) CmdRun(args ...string) error { config, cmd, err := ParseRun(args, nil) if err != nil { return err @@ -1098,16 +1081,16 @@ func CmdRun(args ...string) error { } //create the container - body, statusCode, err := call("POST", "/containers/create", config) + body, statusCode, err := cli.call("POST", "/containers/create", config) //if image not found try to pull it if statusCode == 404 { v := url.Values{} v.Set("fromImage", config.Image) - err = hijack("POST", "/images/create?"+v.Encode(), false) + err = cli.hijack("POST", "/images/create?"+v.Encode(), false) if err != nil { return err } - body, _, err = call("POST", "/containers/create", config) + body, _, err = cli.call("POST", "/containers/create", config) if err != nil { return err } @@ -1142,13 +1125,13 @@ func CmdRun(args ...string) error { } //start the container - _, _, err = call("POST", "/containers/"+out.Id+"/start", nil) + _, _, err = cli.call("POST", "/containers/"+out.Id+"/start", nil) if err != nil { return err } if config.AttachStdin || config.AttachStdout || config.AttachStderr { - if err := hijack("POST", "/containers/"+out.Id+"/attach?"+v.Encode(), config.Tty); err != nil { + if err := cli.hijack("POST", "/containers/"+out.Id+"/attach?"+v.Encode(), config.Tty); err != nil { return err } } @@ -1158,7 +1141,7 @@ func CmdRun(args ...string) error { return nil } -func call(method, path string, data interface{}) ([]byte, int, error) { +func (cli *DockerCli) call(method, path string, data interface{}) ([]byte, int, error) { var params io.Reader if data != nil { buf, err := json.Marshal(data) @@ -1168,7 +1151,7 @@ func call(method, path string, data interface{}) ([]byte, int, error) { params = bytes.NewBuffer(buf) } - req, err := http.NewRequest(method, "http://0.0.0.0:4243"+path, params) + req, err := http.NewRequest(method, fmt.Sprintf("http://%s:%d", cli.host, cli.port)+path, params) if err != nil { return nil, -1, err } @@ -1196,8 +1179,8 @@ func call(method, path string, data interface{}) ([]byte, int, error) { return body, resp.StatusCode, nil } -func stream(method, path string) error { - req, err := http.NewRequest(method, "http://0.0.0.0:4243"+path, nil) +func (cli *DockerCli) stream(method, path string) error { + req, err := http.NewRequest(method, fmt.Sprintf("http://%s:%d%s", cli.host, cli.port, path), nil) if err != nil { return err } @@ -1227,13 +1210,13 @@ func stream(method, path string) error { return nil } -func hijack(method, path string, setRawTerminal bool) error { +func (cli *DockerCli) hijack(method, path string, setRawTerminal bool) error { req, err := http.NewRequest(method, path, nil) if err != nil { return err } req.Header.Set("Content-Type", "plain/text") - dial, err := net.Dial("tcp", "0.0.0.0:4243") + dial, err := net.Dial("tcp", fmt.Sprintf("%s:%d", cli.host, cli.port)) if err != nil { return err } @@ -1244,20 +1227,20 @@ func hijack(method, path string, setRawTerminal bool) error { rwc, br := clientconn.Hijack() defer rwc.Close() - receiveStdout := Go(func() error { + receiveStdout := utils.Go(func() error { _, err := io.Copy(os.Stdout, br) return err }) if setRawTerminal && term.IsTerminal(int(os.Stdin.Fd())) && os.Getenv("NORAW") == "" { - if oldState, err := SetRawTerminal(); err != nil { + if oldState, err := term.SetRawTerminal(); err != nil { return err } else { - defer RestoreTerminal(oldState) + defer term.RestoreTerminal(oldState) } } - sendStdin := Go(func() error { + sendStdin := utils.Go(func() error { _, err := io.Copy(rwc, os.Stdin) if err := rwc.(*net.TCPConn).CloseWrite(); err != nil { fmt.Fprintf(os.Stderr, "Couldn't send EOF: %s\n", err) @@ -1286,3 +1269,12 @@ func Subcmd(name, signature, description string) *flag.FlagSet { } return flags } + +func NewDockerCli(host string, port int) *DockerCli { + return &DockerCli{host, port} +} + +type DockerCli struct { + host string + port int +} diff --git a/container.go b/container.go index d4ebc60c8b..a82ce0291a 100644 --- a/container.go +++ b/container.go @@ -4,6 +4,7 @@ import ( "encoding/json" "flag" "fmt" + "github.com/dotcloud/docker/utils" "github.com/kr/pty" "io" "io/ioutil" @@ -39,8 +40,8 @@ type Container struct { ResolvConfPath string cmd *exec.Cmd - stdout *writeBroadcaster - stderr *writeBroadcaster + stdout *utils.WriteBroadcaster + stderr *utils.WriteBroadcaster stdin io.ReadCloser stdinPipe io.WriteCloser ptyMaster io.Closer @@ -251,9 +252,9 @@ func (container *Container) startPty() error { // Copy the PTYs to our broadcasters go func() { defer container.stdout.CloseWriters() - Debugf("[startPty] Begin of stdout pipe") + utils.Debugf("[startPty] Begin of stdout pipe") io.Copy(container.stdout, ptyMaster) - Debugf("[startPty] End of stdout pipe") + utils.Debugf("[startPty] End of stdout pipe") }() // stdin @@ -262,9 +263,9 @@ func (container *Container) startPty() error { container.cmd.SysProcAttr = &syscall.SysProcAttr{Setctty: true, Setsid: true} go func() { defer container.stdin.Close() - Debugf("[startPty] Begin of stdin pipe") + utils.Debugf("[startPty] Begin of stdin pipe") io.Copy(ptyMaster, container.stdin) - Debugf("[startPty] End of stdin pipe") + utils.Debugf("[startPty] End of stdin pipe") }() } if err := container.cmd.Start(); err != nil { @@ -284,9 +285,9 @@ func (container *Container) start() error { } go func() { defer stdin.Close() - Debugf("Begin of stdin pipe [start]") + utils.Debugf("Begin of stdin pipe [start]") io.Copy(stdin, container.stdin) - Debugf("End of stdin pipe [start]") + utils.Debugf("End of stdin pipe [start]") }() } return container.cmd.Start() @@ -303,8 +304,8 @@ func (container *Container) Attach(stdin io.ReadCloser, stdinCloser io.Closer, s errors <- err } else { go func() { - Debugf("[start] attach stdin\n") - defer Debugf("[end] attach stdin\n") + utils.Debugf("[start] attach stdin\n") + defer utils.Debugf("[end] attach stdin\n") // No matter what, when stdin is closed (io.Copy unblock), close stdout and stderr if cStdout != nil { defer cStdout.Close() @@ -316,12 +317,12 @@ func (container *Container) Attach(stdin io.ReadCloser, stdinCloser io.Closer, s defer cStdin.Close() } if container.Config.Tty { - _, err = CopyEscapable(cStdin, stdin) + _, err = utils.CopyEscapable(cStdin, stdin) } else { _, err = io.Copy(cStdin, stdin) } if err != nil { - Debugf("[error] attach stdin: %s\n", err) + utils.Debugf("[error] attach stdin: %s\n", err) } // Discard error, expecting pipe error errors <- nil @@ -335,8 +336,8 @@ func (container *Container) Attach(stdin io.ReadCloser, stdinCloser io.Closer, s } else { cStdout = p go func() { - Debugf("[start] attach stdout\n") - defer Debugf("[end] attach stdout\n") + utils.Debugf("[start] attach stdout\n") + defer utils.Debugf("[end] attach stdout\n") // If we are in StdinOnce mode, then close stdin if container.Config.StdinOnce { if stdin != nil { @@ -348,7 +349,7 @@ func (container *Container) Attach(stdin io.ReadCloser, stdinCloser io.Closer, s } _, err := io.Copy(stdout, cStdout) if err != nil { - Debugf("[error] attach stdout: %s\n", err) + utils.Debugf("[error] attach stdout: %s\n", err) } errors <- err }() @@ -361,8 +362,8 @@ func (container *Container) Attach(stdin io.ReadCloser, stdinCloser io.Closer, s } else { cStderr = p go func() { - Debugf("[start] attach stderr\n") - defer Debugf("[end] attach stderr\n") + utils.Debugf("[start] attach stderr\n") + defer utils.Debugf("[end] attach stderr\n") // If we are in StdinOnce mode, then close stdin if container.Config.StdinOnce { if stdin != nil { @@ -374,13 +375,13 @@ func (container *Container) Attach(stdin io.ReadCloser, stdinCloser io.Closer, s } _, err := io.Copy(stderr, cStderr) if err != nil { - Debugf("[error] attach stderr: %s\n", err) + utils.Debugf("[error] attach stderr: %s\n", err) } errors <- err }() } } - return Go(func() error { + return utils.Go(func() error { if cStdout != nil { defer cStdout.Close() } @@ -390,14 +391,14 @@ func (container *Container) Attach(stdin io.ReadCloser, stdinCloser io.Closer, s // FIXME: how do clean up the stdin goroutine without the unwanted side effect // of closing the passed stdin? Add an intermediary io.Pipe? for i := 0; i < nJobs; i += 1 { - Debugf("Waiting for job %d/%d\n", i+1, nJobs) + utils.Debugf("Waiting for job %d/%d\n", i+1, nJobs) if err := <-errors; err != nil { - Debugf("Job %d returned error %s. Aborting all jobs\n", i+1, err) + utils.Debugf("Job %d returned error %s. Aborting all jobs\n", i+1, err) return err } - Debugf("Job %d completed successfully\n", i+1) + utils.Debugf("Job %d completed successfully\n", i+1) } - Debugf("All jobs completed successfully\n") + utils.Debugf("All jobs completed successfully\n") return nil }) } @@ -555,13 +556,13 @@ func (container *Container) StdinPipe() (io.WriteCloser, error) { func (container *Container) StdoutPipe() (io.ReadCloser, error) { reader, writer := io.Pipe() container.stdout.AddWriter(writer) - return newBufReader(reader), nil + return utils.NewBufReader(reader), nil } func (container *Container) StderrPipe() (io.ReadCloser, error) { reader, writer := io.Pipe() container.stderr.AddWriter(writer) - return newBufReader(reader), nil + return utils.NewBufReader(reader), nil } func (container *Container) allocateNetwork() error { @@ -609,20 +610,20 @@ func (container *Container) waitLxc() error { func (container *Container) monitor() { // Wait for the program to exit - Debugf("Waiting for process") + utils.Debugf("Waiting for process") // If the command does not exists, try to wait via lxc if container.cmd == nil { if err := container.waitLxc(); err != nil { - Debugf("%s: Process: %s", container.Id, err) + utils.Debugf("%s: Process: %s", container.Id, err) } } else { if err := container.cmd.Wait(); err != nil { // Discard the error as any signals or non 0 returns will generate an error - Debugf("%s: Process: %s", container.Id, err) + utils.Debugf("%s: Process: %s", container.Id, err) } } - Debugf("Process finished") + utils.Debugf("Process finished") var exitCode int = -1 if container.cmd != nil { @@ -633,19 +634,19 @@ func (container *Container) monitor() { container.releaseNetwork() if container.Config.OpenStdin { if err := container.stdin.Close(); err != nil { - Debugf("%s: Error close stdin: %s", container.Id, err) + utils.Debugf("%s: Error close stdin: %s", container.Id, err) } } if err := container.stdout.CloseWriters(); err != nil { - Debugf("%s: Error close stdout: %s", container.Id, err) + utils.Debugf("%s: Error close stdout: %s", container.Id, err) } if err := container.stderr.CloseWriters(); err != nil { - Debugf("%s: Error close stderr: %s", container.Id, err) + utils.Debugf("%s: Error close stderr: %s", container.Id, err) } if container.ptyMaster != nil { if err := container.ptyMaster.Close(); err != nil { - Debugf("%s: Error closing Pty master: %s", container.Id, err) + utils.Debugf("%s: Error closing Pty master: %s", container.Id, err) } } @@ -762,7 +763,7 @@ func (container *Container) RwChecksum() (string, error) { if err != nil { return "", err } - return HashData(rwData) + return utils.HashData(rwData) } func (container *Container) Export() (Archive, error) { @@ -833,7 +834,7 @@ func (container *Container) Unmount() error { // In case of a collision a lookup with Runtime.Get() will fail, and the caller // will need to use a langer prefix, or the full-length container Id. func (container *Container) ShortId() string { - return TruncateId(container.Id) + return utils.TruncateId(container.Id) } func (container *Container) logPath(name string) string { diff --git a/docker/docker.go b/docker/docker.go index 778326a810..c8c1a65603 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -4,6 +4,7 @@ import ( "flag" "fmt" "github.com/dotcloud/docker" + "github.com/dotcloud/docker/utils" "io/ioutil" "log" "os" @@ -17,7 +18,7 @@ var ( ) func main() { - if docker.SelfPath() == "/sbin/init" { + if utils.SelfPath() == "/sbin/init" { // Running in init mode docker.SysInit() return diff --git a/docs/sources/.nojekyll b/docs/sources/.nojekyll deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/docs/sources/CNAME b/docs/sources/CNAME deleted file mode 100644 index 243e482261..0000000000 --- a/docs/sources/CNAME +++ /dev/null @@ -1 +0,0 @@ -docker.io diff --git a/docs/sources/api/docker_remote_api.rst b/docs/sources/api/docker_remote_api.rst index b29fd65d02..03f1d4b9cf 100644 --- a/docs/sources/api/docker_remote_api.rst +++ b/docs/sources/api/docker_remote_api.rst @@ -68,11 +68,12 @@ List containers } ] - :query all: 1 or 0, Show all containers. Only running containers are shown by default + :query all: 1/True/true or 0/False/false, Show all containers. Only running containers are shown by default :query limit: Show ``limit`` last created containers, include non-running ones. :query since: Show only containers created since Id, include non-running ones. :query before: Show only containers created before Id, include non-running ones. :statuscode 200: no error + :statuscode 400: bad parameter :statuscode 500: server error @@ -389,12 +390,13 @@ Attach to a container {{ STREAM }} - :query logs: 1 or 0, return logs. Default 0 - :query stream: 1 or 0, return stream. Default 0 - :query stdin: 1 or 0, if stream=1, attach to stdin. Default 0 - :query stdout: 1 or 0, if logs=1, return stdout log, if stream=1, attach to stdout. Default 0 - :query stderr: 1 or 0, if logs=1, return stderr log, if stream=1, attach to stderr. Default 0 + :query logs: 1/True/true or 0/False/false, return logs. Default false + :query stream: 1/True/true or 0/False/false, return stream. Default false + :query stdin: 1/True/true or 0/False/false, if stream=true, attach to stdin. Default false + :query stdout: 1/True/true or 0/False/false, if logs=true, return stdout log, if stream=true, attach to stdout. Default false + :query stderr: 1/True/true or 0/False/false, if logs=true, return stderr log, if stream=true, attach to stderr. Default false :statuscode 200: no error + :statuscode 400: bad parameter :statuscode 404: no such container :statuscode 500: server error @@ -445,8 +447,9 @@ Remove a container HTTP/1.1 204 OK - :query v: 1 or 0, Remove the volumes associated to the container. Default 0 + :query v: 1/True/true or 0/False/false, Remove the volumes associated to the container. Default false :statuscode 204: no error + :statuscode 400: bad parameter :statuscode 404: no such container :statuscode 500: server error @@ -521,8 +524,9 @@ List Images base [style=invisible] } - :query all: 1 or 0, Show all containers. Only running containers are shown by default + :query all: 1/True/true or 0/False/false, Show all containers. Only running containers are shown by default :statuscode 200: no error + :statuscode 400: bad parameter :statuscode 500: server error @@ -720,8 +724,9 @@ Tag an image into a repository HTTP/1.1 200 OK :query repo: The repository to tag in - :query force: 1 or 0, default 0 + :query force: 1/True/true or 0/False/false, default false :statuscode 200: no error + :statuscode 400: bad parameter :statuscode 404: no such image :statuscode 500: server error diff --git a/docs/sources/commandline/index.rst b/docs/sources/commandline/index.rst index 179903f80d..fecf8e4885 100644 --- a/docs/sources/commandline/index.rst +++ b/docs/sources/commandline/index.rst @@ -9,7 +9,7 @@ Commands Contents: .. toctree:: - :maxdepth: 3 + :maxdepth: 1 cli attach diff --git a/docs/sources/concepts/index.rst b/docs/sources/concepts/index.rst index 9156524999..d8e1af5770 100644 --- a/docs/sources/concepts/index.rst +++ b/docs/sources/concepts/index.rst @@ -12,6 +12,6 @@ Contents: .. toctree:: :maxdepth: 1 - introduction + ../index buildingblocks diff --git a/docs/sources/concepts/introduction.rst b/docs/sources/concepts/introduction.rst index 9c953d8582..fcdd37a791 100644 --- a/docs/sources/concepts/introduction.rst +++ b/docs/sources/concepts/introduction.rst @@ -2,8 +2,6 @@ :description: An introduction to docker and standard containers? :keywords: containers, lxc, concepts, explanation -.. _introduction: - Introduction ============ diff --git a/docs/sources/conf.py b/docs/sources/conf.py index 4c54d8bb62..d443d34052 100644 --- a/docs/sources/conf.py +++ b/docs/sources/conf.py @@ -41,7 +41,7 @@ html_add_permalinks = None # The master toctree document. -master_doc = 'index' +master_doc = 'toctree' # General information about the project. project = u'Docker' diff --git a/docs/sources/dotcloud.yml b/docs/sources/dotcloud.yml deleted file mode 100644 index 5a8f50f9e9..0000000000 --- a/docs/sources/dotcloud.yml +++ /dev/null @@ -1,2 +0,0 @@ -www: - type: static \ No newline at end of file diff --git a/docs/sources/gettingstarted/index.html b/docs/sources/gettingstarted/index.html deleted file mode 100644 index 96175d6dec..0000000000 --- a/docs/sources/gettingstarted/index.html +++ /dev/null @@ -1,210 +0,0 @@ - - - - - - - - - - Docker - the Linux container runtime - - - - - - - - - - - - - - - - - - - - - - - -
-
-

GETTING STARTED

-
-
- -
- -
-
- Docker is still under heavy development. It should not yet be used in production. Check the repo for recent progress. -
-
-
-
-

- - Installing on Ubuntu

- -

Requirements

-
    -
  • Ubuntu 12.04 (LTS) (64-bit)
  • -
  • or Ubuntu 12.10 (quantal) (64-bit)
  • -
-
    -
  1. -

    Install dependencies

    - The linux-image-extra package is only needed on standard Ubuntu EC2 AMIs in order to install the aufs kernel module. -
    sudo apt-get install linux-image-extra-`uname -r`
    - - -
  2. -
  3. -

    Install Docker

    -

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

    -

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

    -
    -
    sudo sh -c "echo 'deb http://ppa.launchpad.net/dotcloud/lxc-docker/ubuntu precise main' >> /etc/apt/sources.list"
    -
    sudo apt-get update
    -
    sudo apt-get install lxc-docker
    -
    - - -
  4. - -
  5. -

    Run!

    - -
    -
    docker run -i -t ubuntu /bin/bash
    -
    -
  6. - Continue with the Hello world example. -
-
- -
-

Contributing to Docker

- -

Want to hack on Docker? Awesome! We have some instructions to get you started. They are probably not perfect, please let us know if anything feels wrong or incomplete.

-
- -
-
-
-

Quick install on other operating systems

-

For other operating systems we recommend and provide a streamlined install with virtualbox, - vagrant and an Ubuntu virtual machine.

- - - -
- -
-

More resources

- -
- - -
-
- Fill out my online form. -
- -
- -
-
-
- - -
-
-
- -
- -
-
- -
-
- -
-
- - - - - - - - - - - diff --git a/docs/sources/index.html b/docs/sources/index.html deleted file mode 100644 index 44a1cc737c..0000000000 --- a/docs/sources/index.html +++ /dev/null @@ -1,314 +0,0 @@ - - - - - - - - - - - Docker - the Linux container engine - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- -
-
- -
-
- - -

The Linux container engine

-
- -
- -
- Docker is an open-source engine which automates the deployment of applications as highly portable, self-sufficient containers which are independent of hardware, language, framework, packaging system and hosting provider. -
- -
- - - - -
- -
-
- -
-
- -
-
-
-
-
- -
-
- -
-
-

Heterogeneous payloads

-

Any combination of binaries, libraries, configuration files, scripts, virtualenvs, jars, gems, tarballs, you name it. No more juggling between domain-specific tools. Docker can deploy and run them all.

-

Any server

-

Docker can run on any x64 machine with a modern linux kernel - whether it's a laptop, a bare metal server or a VM. This makes it perfect for multi-cloud deployments.

-

Isolation

-

Docker isolates processes from each other and from the underlying host, using lightweight containers.

-

Repeatability

-

Because each container is isolated in its own filesystem, they behave the same regardless of where, when, and alongside what they run.

-
-
-
-
-

New! Docker Index

- On the Docker Index you can find and explore pre-made container images. It allows you to share your images and download them. - -

- -
- DOCKER index -
-
-   - - -
-
-
- Fill out my online form. -
- -
-
-
- -
- - - - -
-
-
-
- - John Willis @botchagalupe: IMHO docker is to paas what chef was to Iaas 4 years ago -
-
-
-
- - John Feminella ‏@superninjarobot: So, @getdocker is pure excellence. If you've ever wished for arbitrary, PaaS-agnostic, lxc/aufs Linux containers, this is your jam! -
-
-
-
-
-
- - David Romulan ‏@destructuring: I haven't had this much fun since AWS -
-
-
-
- - Ricardo Gladwell ‏@rgladwell: wow @getdocker is either amazing or totally stupid -
-
- -
-
- -
-
-
- -
- -

Notable features

- -
    -
  • 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.
  • -
  • 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.
  • -
- -

Under the hood

- -

Under the hood, Docker is built on the following components:

- -
    -
  • The cgroup and namespacing capabilities of the Linux kernel;
  • -
  • AUFS, a powerful union filesystem with copy-on-write capabilities;
  • -
  • The Go programming language;
  • -
  • lxc, a set of convenience scripts to simplify the creation of linux containers.
  • -
- -

Who started it

-

- Docker is an open-source implementation of the deployment engine which powers dotCloud, a popular Platform-as-a-Service.

- -

It benefits directly from the experience accumulated over several years of large-scale operation and support of hundreds of thousands - of applications and databases. -

- -
-
- -
- - -
-

Twitter

- - -
- -
-
- -
- - -
-
-
-
- - Docker is a project by dotCloud - -
-
- -
-
- -
-
- -
-
- - - - - - - - - - - - diff --git a/docs/sources/index.rst b/docs/sources/index.rst index fc46ca8255..172f82083c 100644 --- a/docs/sources/index.rst +++ b/docs/sources/index.rst @@ -1,22 +1,127 @@ -:title: docker documentation -:description: docker documentation -:keywords: +:title: Introduction +:description: An introduction to docker and standard containers? +:keywords: containers, lxc, concepts, explanation -Documentation -============= +.. _introduction: -This documentation has the following resources: +Introduction +============ -.. toctree:: - :maxdepth: 1 +Docker - The Linux container runtime +------------------------------------ - concepts/index - installation/index - use/index - examples/index - commandline/index - contributing/index - api/index - faq +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. + +Docker is a great building block for automating distributed systems: large-scale web deployments, database clusters, continuous deployment systems, private PaaS, service-oriented architectures, etc. + + +- **Heterogeneous payloads** Any combination of binaries, libraries, configuration files, scripts, virtualenvs, jars, gems, tarballs, you name it. No more juggling between domain-specific tools. Docker can deploy and run them all. +- **Any server** Docker can run on any x64 machine with a modern linux kernel - whether it's a laptop, a bare metal server or a VM. This makes it perfect for multi-cloud deployments. +- **Isolation** docker isolates processes from each other and from the underlying host, using lightweight containers. +- **Repeatability** Because containers are isolated in their own filesystem, they behave the same regardless of where, when, and alongside what they run. .. image:: concepts/images/lego_docker.jpg + + +What is a Standard Container? +----------------------------- + +Docker defines a unit of software delivery called a Standard Container. The goal of a Standard Container is to encapsulate a software component and all its dependencies in +a format that is self-describing and portable, so that any compliant runtime can run it without extra dependency, regardless of the underlying machine and the contents of the container. + +The spec for Standard Containers is currently work in progress, but it is very straightforward. It mostly defines 1) an image format, 2) a set of standard operations, and 3) an execution environment. + +A great analogy for this is the shipping container. Just like Standard Containers are a fundamental unit of software delivery, shipping containers (http://bricks.argz.com/ins/7823-1/12) are a fundamental unit of physical delivery. + +Standard operations +~~~~~~~~~~~~~~~~~~~ + +Just like shipping containers, Standard Containers define a set of STANDARD OPERATIONS. Shipping containers can be lifted, stacked, locked, loaded, unloaded and labelled. Similarly, standard containers can be started, stopped, copied, snapshotted, downloaded, uploaded and tagged. + + +Content-agnostic +~~~~~~~~~~~~~~~~~~~ + +Just like shipping containers, Standard Containers are CONTENT-AGNOSTIC: all standard operations have the same effect regardless of the contents. A shipping container will be stacked in exactly the same way whether it contains Vietnamese powder coffee or spare Maserati parts. Similarly, Standard Containers are started or uploaded in the same way whether they contain a postgres database, a php application with its dependencies and application server, or Java build artifacts. + + +Infrastructure-agnostic +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Both types of containers are INFRASTRUCTURE-AGNOSTIC: they can be transported to thousands of facilities around the world, and manipulated by a wide variety of equipment. A shipping container can be packed in a factory in Ukraine, transported by truck to the nearest routing center, stacked onto a train, loaded into a German boat by an Australian-built crane, stored in a warehouse at a US facility, etc. Similarly, a standard container can be bundled on my laptop, uploaded to S3, downloaded, run and snapshotted by a build server at Equinix in Virginia, uploaded to 10 staging servers in a home-made Openstack cluster, then sent to 30 production instances across 3 EC2 regions. + + +Designed for automation +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Because they offer the same standard operations regardless of content and infrastructure, Standard Containers, just like their physical counterpart, are extremely well-suited for automation. In fact, you could say automation is their secret weapon. + +Many things that once required time-consuming and error-prone human effort can now be programmed. Before shipping containers, a bag of powder coffee was hauled, dragged, dropped, rolled and stacked by 10 different people in 10 different locations by the time it reached its destination. 1 out of 50 disappeared. 1 out of 20 was damaged. The process was slow, inefficient and cost a fortune - and was entirely different depending on the facility and the type of goods. + +Similarly, before Standard Containers, by the time a software component ran in production, it had been individually built, configured, bundled, documented, patched, vendored, templated, tweaked and instrumented by 10 different people on 10 different computers. Builds failed, libraries conflicted, mirrors crashed, post-it notes were lost, logs were misplaced, cluster updates were half-broken. The process was slow, inefficient and cost a fortune - and was entirely different depending on the language and infrastructure provider. + + +Industrial-grade delivery +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +There are 17 million shipping containers in existence, packed with every physical good imaginable. Every single one of them can be loaded on the same boats, by the same cranes, in the same facilities, and sent anywhere in the World with incredible efficiency. It is embarrassing to think that a 30 ton shipment of coffee can safely travel half-way across the World in *less time* than it takes a software team to deliver its code from one datacenter to another sitting 10 miles away. + +With Standard Containers we can put an end to that embarrassment, by making INDUSTRIAL-GRADE DELIVERY of software a reality. + + +Standard Container Specification +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +(TODO) + +Image format +~~~~~~~~~~~~ + +Standard operations +~~~~~~~~~~~~~~~~~~~ + +- Copy +- Run +- Stop +- Wait +- Commit +- Attach standard streams +- List filesystem changes +- ... + +Execution environment +~~~~~~~~~~~~~~~~~~~~~ + +Root filesystem +^^^^^^^^^^^^^^^ + +Environment variables +^^^^^^^^^^^^^^^^^^^^^ + +Process arguments +^^^^^^^^^^^^^^^^^ + +Networking +^^^^^^^^^^ + +Process namespacing +^^^^^^^^^^^^^^^^^^^ + +Resource limits +^^^^^^^^^^^^^^^ + +Process monitoring +^^^^^^^^^^^^^^^^^^ + +Logging +^^^^^^^ + +Signals +^^^^^^^ + +Pseudo-terminal allocation +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Security +^^^^^^^^ + diff --git a/docs/sources/index/variable.rst b/docs/sources/index/variable.rst new file mode 100644 index 0000000000..efbcfae80c --- /dev/null +++ b/docs/sources/index/variable.rst @@ -0,0 +1,23 @@ +================================= +Docker Index Environment Variable +================================= + +Variable +-------- + +.. code-block:: sh + + DOCKER_INDEX_URL + +Setting this environment variable on the docker server will change the URL docker index. +This address is used in commands such as ``docker login``, ``docker push`` and ``docker pull``. +The docker daemon doesn't need to be restarted for this parameter to take effect. + +Example +------- + +.. code-block:: sh + + docker -d & + export DOCKER_INDEX_URL="https://index.docker.io" + diff --git a/docs/sources/installation/amazon.rst b/docs/sources/installation/amazon.rst index 012c78f401..64ff20f8be 100644 --- a/docs/sources/installation/amazon.rst +++ b/docs/sources/installation/amazon.rst @@ -68,7 +68,7 @@ Docker can now be installed on Amazon EC2 with a single vagrant command. Vagrant If it stalls indefinitely on ``[default] Waiting for SSH to become available...``, Double check your default security zone on AWS includes rights to SSH (port 22) to your container. - If you have an advanced AWS setup, you might want to have a look at the https://github.com/mitchellh/vagrant-aws + If you have an advanced AWS setup, you might want to have a look at https://github.com/mitchellh/vagrant-aws 7. Connect to your machine diff --git a/docs/sources/installation/binaries.rst b/docs/sources/installation/binaries.rst index 2607f3680f..25d13ab68e 100644 --- a/docs/sources/installation/binaries.rst +++ b/docs/sources/installation/binaries.rst @@ -5,48 +5,58 @@ Binaries **Please note this project is currently under heavy development. It should not be used in production.** +**This instruction set is meant for hackers who want to try out Docker on a variety of environments.** Right now, the officially supported distributions are: -- Ubuntu 12.04 (precise LTS) (64-bit) -- Ubuntu 12.10 (quantal) (64-bit) +- :ref:`ubuntu_precise` +- :ref:`ubuntu_raring` -Install dependencies: ---------------------- +But we know people have had success running it under -:: +- Debian +- Suse +- :ref:`arch_linux` - sudo apt-get install lxc bsdtar - sudo apt-get install linux-image-extra-`uname -r` -The linux-image-extra package is needed on standard Ubuntu EC2 AMIs in order to install the aufs kernel module. +Dependencies: +------------- -Install the docker binary: +* 3.8 Kernel +* AUFS filesystem support +* lxc +* bsdtar -:: + +Get the docker binary: +---------------------- + +.. code-block:: bash wget http://get.docker.io/builds/Linux/x86_64/docker-latest.tgz tar -xf docker-latest.tgz - sudo cp ./docker-latest/docker /usr/local/bin - -Note: docker currently only supports 64-bit Linux hosts. Run the docker daemon --------------------- -:: +.. code-block:: bash - sudo docker -d & + # start the docker in daemon mode from the directory you unpacked + sudo ./docker -d & Run your first container! ------------------------- -:: +.. code-block:: bash - docker run -i -t ubuntu /bin/bash + # check your docker version + ./docker version + + # run a container and open an interactive shell in the container + ./docker run -i -t ubuntu /bin/bash diff --git a/docs/sources/installation/index.rst b/docs/sources/installation/index.rst index aaa1cc1959..698d7f8ff1 100644 --- a/docs/sources/installation/index.rst +++ b/docs/sources/installation/index.rst @@ -14,9 +14,9 @@ Contents: ubuntulinux binaries - archlinux vagrant windows amazon rackspace + archlinux upgrading diff --git a/docs/sources/installation/rackspace.rst b/docs/sources/installation/rackspace.rst index 51f13f4732..dfb88aee84 100644 --- a/docs/sources/installation/rackspace.rst +++ b/docs/sources/installation/rackspace.rst @@ -2,220 +2,90 @@ Rackspace Cloud =============== -.. contents:: Table of Contents + Please note this is a community contributed installation path. The only 'official' installation is using the + :ref:`ubuntu_linux` installation path. This version may sometimes be out of date. -Ubuntu 12.04 ------------- -1. Build an Ubuntu 12.04 server using the "Next generation cloud servers", with your desired size. It will give you the password, keep that you will need it later. -2. When the server is up and running ssh into the server. +Installing Docker on Ubuntu proviced by Rackspace is pretty straightforward, and you should mostly be able to follow the +:ref:`ubuntu_linux` installation guide. - .. code-block:: bash +**However, there is one caveat:** - $ ssh root@ +If you are using any linux not already shipping with the 3.8 kernel you will need to install it. And this is a little +more difficult on Rackspace. -3. Once you are logged in you should check what kernel version you are running. +Rackspace boots their servers using grub's menu.lst and does not like non 'virtual' packages (e.g. xen compatible) +kernels there, although they do work. This makes ``update-grub`` to not have the expected result, and you need to +set the kernel manually. - .. code-block:: bash - - $ uname -a - Linux docker-12-04 3.2.0-38-virtual #61-Ubuntu SMP Tue Feb 19 12:37:47 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux - -4. Let's update the server package list - - .. code-block:: bash - - $ apt-get update - -5. Now lets install Docker and it's dependencies. To keep things simple, we will use the Docker install script. It will take a couple of minutes. - - .. code-block:: bash - - $ curl get.docker.io | sudo sh -x - -6. Docker runs best with a new kernel, so lets use 3.8.x - - .. code-block:: bash - - # install the new kernel - $ apt-get install linux-generic-lts-raring - - # update grub so it will use the new kernel after we reboot - $ update-grub - - # update-grub doesn't always work so lets make sure. ``/boot/grub/menu.lst`` was updated. - $ grep 3.8.0- /boot/grub/menu.lst - - # nope it wasn't lets manually update ``/boot/grub/menu.lst`` (make sure you are searching for correct kernel version, look at initial uname -a results.) - $ sed -i s/3.2.0-38-virtual/3.8.0-19-generic/ /boot/grub/menu.lst - - # once again lets make sure it worked. - $ grep 3.8.0- /boot/grub/menu.lst - title Ubuntu 12.04.2 LTS, kernel 3.8.0-19-generic - kernel /boot/vmlinuz-3.8.0-19-generic root=/dev/xvda1 ro quiet splash console=hvc0 - initrd /boot/initrd.img-3.8.0-19-generic - title Ubuntu 12.04.2 LTS, kernel 3.8.0-19-generic (recovery mode) - kernel /boot/vmlinuz-3.8.0-19-generic root=/dev/xvda1 ro quiet splash single - initrd /boot/initrd.img-3.8.0-19-generic - - # much better. - -7. Reboot server (either via command line or console) -8. login again and check to make sure the kernel was updated - - .. code-block:: bash - - $ ssh root@ - $ uname -a - Linux docker-12-04 3.8.0-19-generic #30~precise1-Ubuntu SMP Wed May 1 22:26:36 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux - - # nice 3.8. - -9. Make sure docker is running and test it out. - - .. code-block:: bash - - $ start dockerd - $ docker pull busybox - $ docker run busybox /bin/echo hello world - hello world - -Alternate install -^^^^^^^^^^^^^^^^^ -If you don't want to run the get.docker.io script and want to use packages instead, you can use the docker PPA. Here is how you use it. Replace step 5 with the following 3 steps. - -1. Add the custom package sources to your apt sources list. Copy and paste the following lines at once. +**Do not attempt this on a production machine!** .. code-block:: bash - $ sudo sh -c "echo 'deb http://ppa.launchpad.net/dotcloud/lxc-docker/ubuntu precise main' >> /etc/apt/sources.list" + # update apt + apt-get update + + # install the new kernel + apt-get install linux-generic-lts-raring -2. Update your sources. You will see a warning that GPG signatures cannot be verified. +Great, now you have kernel installed in /boot/, next is to make it boot next time. .. code-block:: bash - $ sudo apt-get update + # find the exact names + find /boot/ -name '*3.8*' + + # this should return some results -3. Now install it, you will see another warning that the package cannot be authenticated. Confirm install. +Now you need to manually edit /boot/grub/menu.lst, you will find a section at the bottom with the existing options. +Copy the top one and substitute the new kernel into that. Make sure the new kernel is on top, and double check kernel +and initrd point to the right files. + +Make special care to double check the kernel and initrd entries. .. code-block:: bash - $ apt-get install lxc-docker + # now edit /boot/grub/menu.lst + vi /boot/grub/menu.lst + +It will probably look something like this: + +:: + + ## ## End Default Options ## + + title Ubuntu 12.04.2 LTS, kernel 3.8.x generic + root (hd0) + kernel /boot/vmlinuz-3.8.0-19-generic root=/dev/xvda1 ro quiet splash console=hvc0 + initrd /boot/initrd.img-3.8.0-19-generic + + title Ubuntu 12.04.2 LTS, kernel 3.2.0-38-virtual + root (hd0) + kernel /boot/vmlinuz-3.2.0-38-virtual root=/dev/xvda1 ro quiet splash console=hvc0 + initrd /boot/initrd.img-3.2.0-38-virtual + + title Ubuntu 12.04.2 LTS, kernel 3.2.0-38-virtual (recovery mode) + root (hd0) + kernel /boot/vmlinuz-3.2.0-38-virtual root=/dev/xvda1 ro quiet splash single + initrd /boot/initrd.img-3.2.0-38-virtual -Ubuntu 12.10 ------------- +Reboot server (either via command line or console) -1. Build an Ubuntu 12.10 server using the "Next generation cloud servers", with your desired size. It will give you the password, keep that you will need it later. -2. When the server is up and running ssh into the server. +.. code-block:: bash - .. code-block:: bash + # reboot - $ ssh root@ +Verify the kernel was updated -3. Once you are logged in you should check what kernel version you are running. +.. code-block:: bash - .. code-block:: bash + uname -a + # Linux docker-12-04 3.8.0-19-generic #30~precise1-Ubuntu SMP Wed May 1 22:26:36 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux - $ uname -a - Linux docker-12-10 3.5.0-25-generic #39-Ubuntu SMP Mon Feb 25 18:26:58 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux + # nice! 3.8. -4. Let's update the server package list - .. code-block:: bash - - $ apt-get update - -5. Now lets install Docker and it's dependencies. To keep things simple, we will use the Docker install script. It will take a couple of minutes. - - .. code-block:: bash - - $ curl get.docker.io | sudo sh -x - -6. Docker runs best with a new kernel, so lets use 3.8.x - - .. code-block:: bash - - # add the ppa to get the right kernel package - $ echo deb http://ppa.launchpad.net/ubuntu-x-swat/q-lts-backport/ubuntu quantal main > /etc/apt/sources.list.d/xswat.list - - # add the key for the ppa - $ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B22AB97AF1CDFA9 - - # update packages again - $ apt-get update - - # install the new kernel - $ apt-get install linux-image-3.8.0-19-generic - - # make sure grub has been updated. - $ grep 3.8.0- /boot/grub/menu.lst - title Ubuntu 12.10, kernel 3.8.0-19-generic - kernel /boot/vmlinuz-3.8.0-19-generic root=/dev/xvda1 ro quiet splash console=hvc0 - initrd /boot/initrd.img-3.8.0-19-generic - title Ubuntu 12.10, kernel 3.8.0-19-generic (recovery mode) - kernel /boot/vmlinuz-3.8.0-19-generic root=/dev/xvda1 ro quiet splash single - initrd /boot/initrd.img-3.8.0-19-generic - - # looks good. If it doesn't work for you, look at the notes for 12.04 to fix. - -7. Reboot server (either via command line or console) -8. login again and check to make sure the kernel was updated - - .. code-block:: bash - - $ ssh root@ - $ uname -a - Linux docker-12-10 3.8.0-19-generic #29~precise2-Ubuntu SMP Fri Apr 19 16:15:35 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux - - # nice 3.8. - -9. Make sure docker is running and test it out. - - .. code-block:: bash - - $ start dockerd - $ docker pull busybox - $ docker run busybox /bin/echo hello world - hello world - -Ubuntu 13.04 ------------- - -1. Build an Ubuntu 13.04 server using the "Next generation cloud servers", with your desired size. It will give you the password, keep that you will need it later. -2. When the server is up and running ssh into the server. - - .. code-block:: bash - - $ ssh root@ - -3. Once you are logged in you should check what kernel version you are running. - - .. code-block:: bash - - $ uname -a - Linux docker-1304 3.8.0-19-generic #29-Ubuntu SMP Wed Apr 17 18:16:28 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux - -4. Let's update the server package list - - .. code-block:: bash - - $ apt-get update - -5. Now lets install Docker and it's dependencies. To keep things simple, we will use the Docker install script. It will take a couple of minutes. - - .. code-block:: bash - - $ curl get.docker.io | sudo sh -x - -6. Make sure docker is running and test it out. - - .. code-block:: bash - - $ start dockerd - $ docker pull busybox - $ docker run busybox /bin/echo hello world - hello world - \ No newline at end of file +Now you can finish with the :ref:`ubuntu_linux` instructions. \ No newline at end of file diff --git a/docs/sources/installation/ubuntulinux.rst b/docs/sources/installation/ubuntulinux.rst index 972844cc18..de4a2bb9ca 100644 --- a/docs/sources/installation/ubuntulinux.rst +++ b/docs/sources/installation/ubuntulinux.rst @@ -5,20 +5,39 @@ Ubuntu Linux **Please note this project is currently under heavy development. It should not be used in production.** +Right now, the officially supported distribution are: -Right now, the officially supported distributions are: +- :ref:`ubuntu_precise` +- :ref:`ubuntu_raring` + +Docker has the following dependencies + +* Linux kernel 3.8 +* AUFS file system support (we are working on BTRFS support as an alternative) + +.. _ubuntu_precise: + +Ubuntu Precise 12.04 (LTS) (64-bit) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This installation path should work at all times. -- Ubuntu 12.04 (precise LTS) (64-bit) -- Ubuntu 12.10 (quantal) (64-bit) Dependencies ------------ -The linux-image-extra package is only needed on standard Ubuntu EC2 AMIs in order to install the aufs kernel module. +**Linux kernel 3.8** + +Due to a bug in LXC docker works best on the 3.8 kernel. Precise comes with a 3.2 kernel, so we need to upgrade it. The kernel we install comes with AUFS built in. + .. code-block:: bash - sudo apt-get install linux-image-extra-`uname -r` lxc bsdtar + # install the backported kernel + sudo apt-get update && sudo apt-get install linux-image-3.8.0-19-generic + + # reboot + sudo reboot Installation @@ -28,33 +47,77 @@ Docker is available as a Ubuntu PPA (Personal Package Archive), `hosted on launchpad `_ which makes installing Docker on Ubuntu very easy. - - -Add the custom package sources to your apt sources list. Copy and paste the following lines at once. - .. code-block:: bash - sudo sh -c "echo 'deb http://ppa.launchpad.net/dotcloud/lxc-docker/ubuntu precise main' >> /etc/apt/sources.list" - - -Update your sources. You will see a warning that GPG signatures cannot be verified. - -.. code-block:: bash + # Add the PPA sources to your apt sources list. + sudo sh -c "echo 'deb http://ppa.launchpad.net/dotcloud/lxc-docker/ubuntu precise main' > /etc/apt/sources.list.d/lxc-docker.list" + # Update your sources, you will see a warning. sudo apt-get update - -Now install it, you will see another warning that the package cannot be authenticated. Confirm install. - -.. code-block:: bash - - apt-get install lxc-docker + # Install, you will see another warning that the package cannot be authenticated. Confirm install. + sudo apt-get install lxc-docker Verify it worked .. code-block:: bash - docker + # download the base 'ubuntu' container and run bash inside it while setting up an interactive shell + docker run -i -t ubuntu /bin/bash + + # type 'exit' to exit + + +**Done!**, now continue with the :ref:`hello_world` example. + +.. _ubuntu_raring: + +Ubuntu Raring 13.04 (64 bit) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Dependencies +------------ + +**AUFS filesystem support** + +Ubuntu Raring already comes with the 3.8 kernel, so we don't need to install it. However, not all systems +have AUFS filesystem support enabled, so we need to install it. + +.. code-block:: bash + + sudo apt-get update + sudo apt-get install linux-image-extra-`uname -r` + +Installation +------------ + +Docker is available as a Ubuntu PPA (Personal Package Archive), +`hosted on launchpad `_ +which makes installing Docker on Ubuntu very easy. + + +Add the custom package sources to your apt sources list. + +.. code-block:: bash + + # add the sources to your apt + sudo add-apt-repository ppa:dotcloud/lxc-docker + + # update + sudo apt-get update + + # install + sudo apt-get install lxc-docker + + +Verify it worked + +.. code-block:: bash + + # download the base 'ubuntu' container and run bash inside it while setting up an interactive shell + docker run -i -t ubuntu /bin/bash + + # type exit to exit **Done!**, now continue with the :ref:`hello_world` example. diff --git a/docs/sources/installation/upgrading.rst b/docs/sources/installation/upgrading.rst index a5172b6d76..8dfde73891 100644 --- a/docs/sources/installation/upgrading.rst +++ b/docs/sources/installation/upgrading.rst @@ -3,38 +3,53 @@ Upgrading ============ -These instructions are for upgrading your Docker binary for when you had a custom (non package manager) installation. -If you istalled docker using apt-get, use that to upgrade. +**These instructions are for upgrading Docker** -Get the latest docker binary: +After normal installation +------------------------- -:: +If you installed Docker normally using apt-get or used Vagrant, use apt-get to upgrade. - wget http://get.docker.io/builds/$(uname -s)/$(uname -m)/docker-latest.tgz +.. code-block:: bash + + # update your sources list + sudo apt-get update + + # install the latest + sudo apt-get install lxc-docker +After manual installation +------------------------- -Unpack it to your current dir +If you installed the Docker binary -:: +.. code-block:: bash + + # kill the running docker daemon + killall docker + + +.. code-block:: bash + + # get the latest binary + wget http://get.docker.io/builds/Linux/x86_64/docker-latest.tgz + + +.. code-block:: bash + + # Unpack it to your current dir tar -xf docker-latest.tgz -Stop your current daemon. How you stop your daemon depends on how you started it. +Start docker in daemon mode (-d) and disconnect (&) starting ./docker will start the version in your current dir rather than a version which +might reside in your path. -- If you started the daemon manually (``sudo docker -d``), you can just kill the process: ``killall docker`` -- If the process was started using upstart (the ubuntu startup daemon), you may need to use that to stop it - - -Start docker in daemon mode (-d) and disconnect (&) starting ./docker will start the version in your current dir rather -than the one in your PATH. - -Now start the daemon - -:: +.. code-block:: bash + # start the new version sudo ./docker -d & diff --git a/docs/sources/installation/vagrant.rst b/docs/sources/installation/vagrant.rst index 465a6c3388..d1a76b5a2b 100644 --- a/docs/sources/installation/vagrant.rst +++ b/docs/sources/installation/vagrant.rst @@ -1,14 +1,10 @@ .. _install_using_vagrant: -Using Vagrant -============= +Using Vagrant (Mac, Linux) +========================== - Please note this is a community contributed installation path. The only 'official' installation is using the - :ref:`ubuntu_linux` installation path. This version may sometimes be out of date. - -**Requirements:** -This guide will setup a new virtual machine with docker installed on your computer. This works on most operating +This guide will setup a new virtualbox virtual machine with docker installed on your computer. This works on most operating systems, including MacOX, Windows, Linux, FreeBSD and others. If you can install these and have at least 400Mb RAM to spare you should be good. diff --git a/docs/sources/installation/windows.rst b/docs/sources/installation/windows.rst index a89d3a9014..230ac78051 100644 --- a/docs/sources/installation/windows.rst +++ b/docs/sources/installation/windows.rst @@ -3,8 +3,8 @@ :keywords: Docker, Docker documentation, Windows, requirements, virtualbox, vagrant, git, ssh, putty, cygwin -Windows (with Vagrant) -====================== +Using Vagrant (Windows) +======================= Please note this is a community contributed installation path. The only 'official' installation is using the :ref:`ubuntu_linux` installation path. This version may be out of date because it depends on some binaries to be updated and published diff --git a/docs/sources/nginx.conf b/docs/sources/nginx.conf deleted file mode 100644 index 97ffd2c0e5..0000000000 --- a/docs/sources/nginx.conf +++ /dev/null @@ -1,6 +0,0 @@ - -# rule to redirect original links created when hosted on github pages -rewrite ^/documentation/(.*).html http://docs.docker.io/en/latest/$1/ permanent; - -# rewrite the stuff which was on the current page -rewrite ^/gettingstarted.html$ /gettingstarted/ permanent; diff --git a/docs/sources/toctree.rst b/docs/sources/toctree.rst new file mode 100644 index 0000000000..09f2a7af5b --- /dev/null +++ b/docs/sources/toctree.rst @@ -0,0 +1,22 @@ +:title: docker documentation +:description: docker documentation +:keywords: + +Documentation +============= + +This documentation has the following resources: + +.. toctree:: + :titlesonly: + + concepts/index + installation/index + use/index + examples/index + commandline/index + contributing/index + api/index + faq + +.. image:: concepts/images/lego_docker.jpg diff --git a/docs/theme/docker/layout.html b/docs/theme/docker/layout.html index 1189ceb14b..aa5a24d496 100755 --- a/docs/theme/docker/layout.html +++ b/docs/theme/docker/layout.html @@ -66,7 +66,7 @@