github.com/walkingsparrow/docker@v1.4.2-0.20151218153551-b708a2249bfa/api/client/lib/exec.go (about) 1 package lib 2 3 import ( 4 "encoding/json" 5 6 "github.com/docker/docker/api/types" 7 "github.com/docker/docker/runconfig" 8 ) 9 10 // ContainerExecCreate creates a new exec configuration to run an exec process. 11 func (cli *Client) ContainerExecCreate(config runconfig.ExecConfig) (types.ContainerExecCreateResponse, error) { 12 var response types.ContainerExecCreateResponse 13 resp, err := cli.post("/containers/"+config.Container+"/exec", nil, config, nil) 14 if err != nil { 15 return response, err 16 } 17 defer ensureReaderClosed(resp) 18 err = json.NewDecoder(resp.body).Decode(&response) 19 return response, err 20 } 21 22 // ContainerExecStart starts an exec process already create in the docker host. 23 func (cli *Client) ContainerExecStart(execID string, config types.ExecStartCheck) error { 24 resp, err := cli.post("/exec/"+execID+"/start", nil, config, nil) 25 ensureReaderClosed(resp) 26 return err 27 } 28 29 // ContainerExecAttach attaches a connection to an exec process in the server. 30 // It returns a types.HijackedConnection with the hijacked connection 31 // and the a reader to get output. It's up to the called to close 32 // the hijacked connection by calling types.HijackedResponse.Close. 33 func (cli *Client) ContainerExecAttach(execID string, config runconfig.ExecConfig) (types.HijackedResponse, error) { 34 headers := map[string][]string{"Content-Type": {"application/json"}} 35 return cli.postHijacked("/exec/"+execID+"/start", nil, config, headers) 36 } 37 38 // ContainerExecInspect returns information about a specific exec process on the docker host. 39 func (cli *Client) ContainerExecInspect(execID string) (types.ContainerExecInspect, error) { 40 var response types.ContainerExecInspect 41 resp, err := cli.get("/exec/"+execID+"/json", nil, nil) 42 if err != nil { 43 return response, err 44 } 45 defer ensureReaderClosed(resp) 46 47 err = json.NewDecoder(resp.body).Decode(&response) 48 return response, err 49 }