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 {

View File

@@ -7,4 +7,5 @@ type Manager interface {
Pause() error
Unpause() error
Restart() error
Exec(cmd []string) error
}

View File

@@ -29,3 +29,7 @@ func (m *Mock) Unpause() error {
func (m *Mock) Restart() error {
return nil
}
func (m *Mock) Exec(cmd []string) error {
return nil
}

View File

@@ -29,3 +29,7 @@ func (rc *Runc) Unpause() error {
func (rc *Runc) Restart() error {
return nil
}
func (rc *Runc) Exec(cmd []string) error {
return nil
}