Container running modes
Docker has two container running modes, foreground and detached. Let's begin with the default one, the foreground mode.
Foreground
In the foreground mode, the console you are using to execute docker run
will be attached to standard input, output, and error streams. This is the default; Docker will attach STDIN
, STDOUT
and STDERR
streams to your shell console. If you need to, you can change this behavior and use the -a
switch for the docker run
command. As a parameter for the -a
switch, you use the name of the stream you want to attach to the console. For example:
$ docker run -a stdin -a stdout -i -t centos /bin/bash
The preceding command will attach both stdin
and stdout
streams to your console.
The useful docker run
options are the -i
or --interactive
(for keeping STDIN
stream open, even if not attached) and -t
or -tty
(for attaching a pseudo-tty
) switches, commonly used together as -it
which you will need to use to allocate a pseudo-tty
console for the process running...