Added note about process interaction with container in detached mode

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

Added note about process interaction with container in detached mode

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>
This commit is contained in:
Dharmit Shah 2015-08-23 18:08:50 +05:30 committed by Tibor Vass
parent 898614f30a
commit 23effb34d7
1 changed files with 24 additions and 6 deletions

View File

@ -87,12 +87,30 @@ default foreground mode:
### Detached (-d) ### Detached (-d)
In detached mode (`-d=true` or just `-d`), all I/O should be done To start a container in detached mode, you use `-d=true` or just `-d` option. By
through network connections or shared volumes because the container is design, containers started in detached mode exit when the root process used to
no longer listening to the command line where you executed `docker run`. run the container exits. A container in detached mode cannot be automatically
You can reattach to a detached container with `docker` removed when it stops, this means you cannot use the `--rm` option with `-d` option.
[*attach*](/reference/commandline/attach). If you choose to run a
container in the detached mode, then you cannot use the `--rm` option. Do not pass a `service x start` command to a detached container. For example, this
command attempts to start the `nginx` service.
$ docker run -d -p 80:80 my_image service nginx start
This succeeds in starting the `nginx` service inside the container. However, it
fails the detached container paradigm in that, the root process (`service nginx
start`) returns and the detached container stops as designed. As a result, the
`nginx` service is started but could not be used. Instead, to start a process
such as the `nginx` web server do the following:
$ docker run -d -p 80:80 my_image nginx -g 'daemon off;'
To do input/output with a detached container use network connections or shared
volumes. These are required because the container is no longer listening to the
command line where `docker run` was run.
To reattach to a detached container, use `docker`
[*attach*](/reference/commandline/attach) command.
### Foreground ### Foreground