Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confuse about docker's -i "Keep STDIN open even if not attached"

Tags:

docker

The -i flag is described as "Keep STDIN open even if not attached", but Docker run reference also says:

If you do not specify -a then Docker will attach all standard streams.

So, by default, stdin is attached, but not opened? I think it doesn't make any sense when STDIN is attached but not opened, right?

like image 638
YON Avatar asked Apr 12 '16 04:04

YON


1 Answers

The exact code associated with that documentation is:

// If neither -d or -a are set, attach to everything by default
if len(flAttach) == 0 && !*flDetach {
    if !*flDetach {
        flAttach.Set("stdout")
        flAttach.Set("stderr")
        if *flStdin {
            flAttach.Set("stdin")
        }
    }
}

With:

flStdin := cmd.Bool("i", false, "Keep stdin open even if not attached")

In other words, stdin is attached only if -i is set.

        if *flStdin {
            flAttach.Set("stdin")
        }

In that sense, "all" standard streams isn't accurate.

As commented below, that code (referenced by the doc) has since changed to:

cmd.Var(&flAttach, []string{"a", "-attach"}, "Attach to STDIN, STDOUT or STDERR")

-a does not man anymore "attach all streams", but "specify which streams you want attached".

var (
    attachStdin  = flAttach.Get("stdin")
    attachStdout = flAttach.Get("stdout")
    attachStderr = flAttach.Get("stderr")
)

-i remains a valid option:

if *flStdin {
    attachStdin = true
}
like image 111
VonC Avatar answered Sep 18 '22 03:09

VonC