Do not allow to close /dev/stdin

This commit is contained in:
Stanislav Pavlovichev 2018-10-26 17:08:33 +03:00
parent a26fc9169c
commit d59c91a461
1 changed files with 11 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package manager
import (
"fmt"
api "github.com/fsouza/go-dockerclient"
"io"
"os"
)
@ -18,6 +19,15 @@ func NewDocker(client *api.Client, id string) *Docker {
}
}
// Do not allow to close reader (i.e. /dev/stdin which docker client tries to close after command execution)
type noClosableReader struct {
wrappedReader io.Reader
}
func (w *noClosableReader) Read(p []byte) (n int, err error) {
return w.wrappedReader.Read(p)
}
func (dc *Docker) Exec(cmd []string) error {
execCmd, err := dc.client.CreateExec(api.CreateExecOptions{
AttachStdin: true,
@ -33,7 +43,7 @@ func (dc *Docker) Exec(cmd []string) error {
}
return dc.client.StartExec(execCmd.ID, api.StartExecOptions{
InputStream: os.Stdin,
InputStream: &noClosableReader{os.Stdin},
OutputStream: os.Stdout,
ErrorStream: os.Stderr,
RawTerminal: true,