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

前端 未结 1 1232
青春惊慌失措
青春惊慌失措 2021-02-14 14:41

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 Docke

1条回答
  •  北海茫月
    2021-02-14 15:23

    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
    }
    

    0 讨论(0)
提交回复
热议问题