This is obviously a newbie question. The docker run man page is not clear about this. This is what it says about foreground mode, which I understand to be the same as attached mode:
In foreground mode (the default when -d is not specified), docker run can start the process in the container and attach the console to the process’s standard input, output, and standard error. It can even pretend to be a TTY (this is what most command line executables expect) and pass along signals.
My question: In foreground mode, it can do various things, but options like -i and -t are required. What if I start a container without providing a TTY (-t) and without keeping stdin open (-i)?
In other words: When I start a container started like this, without any option:
docker run MY-IMAGE
I get the host’s login prompt, as expected. But how does this differ from:
I think the key point from the documentation you quote is that -it is “what most command line executables expect”, but IME the typical container isn’t a command-line executable, it’s a server process.
Thanks David, I am slowly getting there. So my container ran in the foreground, but its main process, a shell (it was a Ubuntu container), didn’t find a terminal and exited.
I do have a follow-up question to the same topic:
-t allocates a terminal. Yes, I can see the prompt. But when I enter something, I don’t get anything back from the shell, and ^C kills the shell and thus the container. This behaviour surprises me.
To talk to the bash in the container, I also need -i, although the doc says that this option means “Keep STDIN open even if not attached”. Well, it is attached, so why do I need -i?