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>
| ... | ... |
@@ -87,12 +87,30 @@ default foreground mode: |
| 87 | 87 |
|
| 88 | 88 |
### Detached (-d) |
| 89 | 89 |
|
| 90 |
-In detached mode (`-d=true` or just `-d`), all I/O should be done |
|
| 91 |
-through network connections or shared volumes because the container is |
|
| 92 |
-no longer listening to the command line where you executed `docker run`. |
|
| 93 |
-You can reattach to a detached container with `docker` |
|
| 94 |
-[*attach*](/reference/commandline/attach). If you choose to run a |
|
| 95 |
-container in the detached mode, then you cannot use the `--rm` option. |
|
| 90 |
+To start a container in detached mode, you use `-d=true` or just `-d` option. By |
|
| 91 |
+design, containers started in detached mode exit when the root process used to |
|
| 92 |
+run the container exits. A container in detached mode cannot be automatically |
|
| 93 |
+removed when it stops, this means you cannot use the `--rm` option with `-d` option. |
|
| 94 |
+ |
|
| 95 |
+Do not pass a `service x start` command to a detached container. For example, this |
|
| 96 |
+command attempts to start the `nginx` service. |
|
| 97 |
+ |
|
| 98 |
+ $ docker run -d -p 80:80 my_image service nginx start |
|
| 99 |
+ |
|
| 100 |
+This succeeds in starting the `nginx` service inside the container. However, it |
|
| 101 |
+fails the detached container paradigm in that, the root process (`service nginx |
|
| 102 |
+start`) returns and the detached container stops as designed. As a result, the |
|
| 103 |
+`nginx` service is started but could not be used. Instead, to start a process |
|
| 104 |
+such as the `nginx` web server do the following: |
|
| 105 |
+ |
|
| 106 |
+ $ docker run -d -p 80:80 my_image nginx -g 'daemon off;' |
|
| 107 |
+ |
|
| 108 |
+To do input/output with a detached container use network connections or shared |
|
| 109 |
+volumes. These are required because the container is no longer listening to the |
|
| 110 |
+command line where `docker run` was run. |
|
| 111 |
+ |
|
| 112 |
+To reattach to a detached container, use `docker` |
|
| 113 |
+[*attach*](/reference/commandline/attach) command. |
|
| 96 | 114 |
|
| 97 | 115 |
### Foreground |
| 98 | 116 |
|