Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 35cab46

Browse files
author
Vincent Demeester
authored
Merge pull request #485 from ArnoBouts/runwithouttty
Add run option DisableTty
2 parents 64323fb + 2e39183 commit 35cab46

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

docker/container/container.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ func (c *Container) Run(ctx context.Context, configOverride *config.ServiceConfi
180180
errCh chan error
181181
out, stderr io.Writer
182182
in io.ReadCloser
183+
inFd uintptr
183184
)
184185

185186
if configOverride.StdinOpen {
@@ -202,14 +203,17 @@ func (c *Container) Run(ctx context.Context, configOverride *config.ServiceConfi
202203
return -1, err
203204
}
204205

205-
// set raw terminal
206-
inFd, _ := term.GetFdInfo(in)
207-
state, err := term.SetRawTerminal(inFd)
208-
if err != nil {
209-
return -1, err
206+
if configOverride.StdinOpen {
207+
// set raw terminal
208+
inFd, _ = term.GetFdInfo(in)
209+
state, err := term.SetRawTerminal(inFd)
210+
if err != nil {
211+
return -1, err
212+
}
213+
// restore raw terminal
214+
defer term.RestoreTerminal(inFd, state)
210215
}
211-
// restore raw terminal
212-
defer term.RestoreTerminal(inFd, state)
216+
213217
// holdHijackedConnection (in goroutine)
214218
errCh = promise.Go(func() error {
215219
return holdHijackedConnection(configOverride.Tty, in, out, stderr, resp)

docker/service/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func (s *Service) Run(ctx context.Context, commandParts []string, options option
257257
return -1, err
258258
}
259259

260-
configOverride := &config.ServiceConfig{Command: commandParts, Tty: true, StdinOpen: true}
260+
configOverride := &config.ServiceConfig{Command: commandParts, Tty: !options.DisableTty, StdinOpen: !options.DisableTty}
261261

262262
c, err := s.createContainer(ctx, namer, "", configOverride, true)
263263
if err != nil {

project/options/types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ type Create struct {
3030

3131
// Run holds options of compose run.
3232
type Run struct {
33-
Detached bool
33+
Detached bool
34+
DisableTty bool
3435
}
3536

3637
// Up holds options of compose up.

0 commit comments

Comments
 (0)