Exec using API

This commit is contained in:
Stanislav Pavlovichev
2018-10-13 08:33:53 +03:00
parent e68f7ba96a
commit 967a87a65f
7 changed files with 105 additions and 17 deletions

View File

@@ -3,6 +3,7 @@ package manager
import (
"fmt"
api "github.com/fsouza/go-dockerclient"
"os"
)
type Docker struct {
@@ -17,6 +18,28 @@ func NewDocker(client *api.Client, id string) *Docker {
}
}
func (dc *Docker) Exec(cmd []string) error {
execCmd, err := dc.client.CreateExec(api.CreateExecOptions{
AttachStdin: true,
AttachStdout: true,
AttachStderr: true,
Cmd: cmd,
Container: dc.id,
Tty: true,
})
if err != nil {
return err
}
return dc.client.StartExec(execCmd.ID, api.StartExecOptions{
InputStream: os.Stdin,
OutputStream: os.Stdout,
ErrorStream: os.Stderr,
RawTerminal: true,
})
}
func (dc *Docker) Start() error {
c, err := dc.client.InspectContainer(dc.id)
if err != nil {