mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
Exec using API
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -7,4 +7,5 @@ type Manager interface {
|
||||
Pause() error
|
||||
Unpause() error
|
||||
Restart() error
|
||||
Exec(cmd []string) error
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user