mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #969 from dotcloud/fix_logs
- Remote API: Fix a bug which caused 'docker logs' to fail
This commit is contained in:
commit
09dd7f14de
3 changed files with 15 additions and 7 deletions
2
api.go
2
api.go
|
@ -816,6 +816,7 @@ func createRouter(srv *Server, logging bool) (*mux.Router, error) {
|
||||||
localFct := fct
|
localFct := fct
|
||||||
f := func(w http.ResponseWriter, r *http.Request) {
|
f := func(w http.ResponseWriter, r *http.Request) {
|
||||||
utils.Debugf("Calling %s %s", localMethod, localRoute)
|
utils.Debugf("Calling %s %s", localMethod, localRoute)
|
||||||
|
|
||||||
if logging {
|
if logging {
|
||||||
log.Println(r.Method, r.RequestURI)
|
log.Println(r.Method, r.RequestURI)
|
||||||
}
|
}
|
||||||
|
@ -836,6 +837,7 @@ func createRouter(srv *Server, logging bool) (*mux.Router, error) {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := localFct(srv, version, w, r, mux.Vars(r)); err != nil {
|
if err := localFct(srv, version, w, r, mux.Vars(r)); err != nil {
|
||||||
httpError(w, err)
|
httpError(w, err)
|
||||||
}
|
}
|
||||||
|
|
12
commands.go
12
commands.go
|
@ -1036,10 +1036,10 @@ func (cli *DockerCli) CmdLogs(args ...string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := cli.stream("POST", "/containers/"+cmd.Arg(0)+"/attach?logs=1&stdout=1", nil, os.Stdout); err != nil {
|
if err := cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?logs=1&stdout=1", false, nil, os.Stdout); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := cli.stream("POST", "/containers/"+cmd.Arg(0)+"/attach?logs=1&stderr=1", nil, os.Stderr); err != nil {
|
if err := cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?logs=1&stderr=1", false, nil, os.Stderr); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -1370,6 +1370,7 @@ func (cli *DockerCli) stream(method, path string, in io.Reader, out io.Writer) e
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode < 200 || resp.StatusCode >= 400 {
|
if resp.StatusCode < 200 || resp.StatusCode >= 400 {
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1407,19 +1408,24 @@ func (cli *DockerCli) stream(method, path string, in io.Reader, out io.Writer) e
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in *os.File, out io.Writer) error {
|
func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in *os.File, out io.Writer) error {
|
||||||
|
|
||||||
req, err := http.NewRequest(method, fmt.Sprintf("/v%g%s", APIVERSION, path), nil)
|
req, err := http.NewRequest(method, fmt.Sprintf("/v%g%s", APIVERSION, path), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
req.Header.Set("User-Agent", "Docker-Client/"+VERSION)
|
||||||
req.Header.Set("Content-Type", "plain/text")
|
req.Header.Set("Content-Type", "plain/text")
|
||||||
|
|
||||||
dial, err := net.Dial(cli.proto, cli.addr)
|
dial, err := net.Dial(cli.proto, cli.addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
clientconn := httputil.NewClientConn(dial, nil)
|
clientconn := httputil.NewClientConn(dial, nil)
|
||||||
clientconn.Do(req)
|
|
||||||
defer clientconn.Close()
|
defer clientconn.Close()
|
||||||
|
|
||||||
|
// Server hijacks the connection, error 'connection closed' expected
|
||||||
|
clientconn.Do(req)
|
||||||
|
|
||||||
rwc, br := clientconn.Hijack()
|
rwc, br := clientconn.Hijack()
|
||||||
defer rwc.Close()
|
defer rwc.Close()
|
||||||
|
|
||||||
|
|
|
@ -979,17 +979,17 @@ func (srv *Server) ContainerAttach(name string, logs, stream, stdin, stdout, std
|
||||||
if stdout {
|
if stdout {
|
||||||
cLog, err := container.ReadLog("stdout")
|
cLog, err := container.ReadLog("stdout")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Debugf(err.Error())
|
utils.Debugf("Error reading logs (stdout): %s", err)
|
||||||
} else if _, err := io.Copy(out, cLog); err != nil {
|
} else if _, err := io.Copy(out, cLog); err != nil {
|
||||||
utils.Debugf(err.Error())
|
utils.Debugf("Error streaming logs (stdout): %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if stderr {
|
if stderr {
|
||||||
cLog, err := container.ReadLog("stderr")
|
cLog, err := container.ReadLog("stderr")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Debugf(err.Error())
|
utils.Debugf("Error reading logs (stderr): %s", err)
|
||||||
} else if _, err := io.Copy(out, cLog); err != nil {
|
} else if _, err := io.Copy(out, cLog); err != nil {
|
||||||
utils.Debugf(err.Error())
|
utils.Debugf("Error streaming logs (stderr): %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue