1

I am newbie on Docker. Seems the following pipe prints nothing. If I am right, the -a stdin attaches my host stdin to the container process's stdin.

~ $ echo test | docker run -a stdin -a stdout -a stderr --rm alpine cat -

When I add the -i option, it does print the "test":

~ $ echo test | docker run -i -a stdin -a stdout -a stderr --rm alpine cat -
test

Why must we append the -i option?

I did read this post Confused about Docker -t option to Allocate a pseudo-TTY, but still confused by options like -a, -d, -t, -i. For example, is there any difference between the following two runs?

~ $ docker run -a stdin -a stdout -it ubuntu /bin/bash

~ $ docker run -it ubuntu /bin/bash

After some search, I think the -i option's purpose is to make the stdin of PID 1 open which by default is closed.

Zachary
  • 1,633
  • 2
  • 22
  • 34
  • I think those streams are attached by default. Eg. you can simplify this example to `echo foo | docker run -i --rm alpine cat -` – Nick ODell Apr 06 '22 at 04:48
  • @NickODell, yep. But why `-i` prints the text while `-a stdin` not. – Zachary Apr 06 '22 at 05:04
  • well technically, the help says this for -i `Keep STDIN open even if not attached`. So I would think that if its attached its kept open without -i but when its not attached you can keep it open with -i. In that sense using -a STDIN should work the same as -i. Maybe you need to uppercase it. – The Fool Apr 08 '22 at 14:11
  • Well I just tried `docker run -i busybox cat < text.txt` works but `docker run -a STDIN -a STDOUT -a STDERR busybox cat < text.txt` doesnt. – The Fool Apr 08 '22 at 14:14
  • @TheFool yep, `-a STDIN` does *not* pipe/redirect data to the container process. That's the part I don't understand. – Zachary Apr 10 '22 at 02:50

0 Answers0