github.com/kobeld/docker@v1.12.0-rc1/docs/reference/commandline/attach.md (about)

     1  <!--[metadata]>
     2  +++
     3  title = "attach"
     4  description = "The attach command description and usage"
     5  keywords = ["attach, running, container"]
     6  [menu.main]
     7  parent = "smn_cli"
     8  +++
     9  <![end-metadata]-->
    10  
    11  # attach
    12  
    13      Usage: docker attach [OPTIONS] CONTAINER
    14  
    15      Attach to a running container
    16  
    17        --detach-keys="<sequence>"       Set up escape key sequence
    18        --help                           Print usage
    19        --no-stdin                       Do not attach STDIN
    20        --sig-proxy=true                 Proxy all received signals to the process
    21  
    22  The `docker attach` command allows you to attach to a running container using
    23  the container's ID or name, either to view its ongoing output or to control it
    24  interactively. You can attach to the same contained process multiple times
    25  simultaneously, screen sharing style, or quickly view the progress of your
    26  detached  process.
    27  
    28  To stop a container, use `CTRL-c`. This key sequence sends `SIGKILL` to the
    29  container. If `--sig-proxy` is true (the default),`CTRL-c` sends a `SIGINT` to
    30  the container. You can detach from a container and leave it running using the
    31   `CTRL-p CTRL-q` key sequence.
    32  
    33  > **Note:**
    34  > A process running as PID 1 inside a container is treated specially by
    35  > Linux: it ignores any signal with the default action. So, the process
    36  > will not terminate on `SIGINT` or `SIGTERM` unless it is coded to do
    37  > so.
    38  
    39  It is forbidden to redirect the standard input of a `docker attach` command
    40  while attaching to a tty-enabled container (i.e.: launched with `-t`).
    41  
    42  While a client is connected to container's stdio using `docker attach`, Docker 
    43  uses a ~1MB memory buffer to maximize the throughput of the application. If 
    44  this buffer is filled, the speed of the API connection will start to have an 
    45  effect on the process output writing speed. This is similar to other 
    46  applications like SSH. Because of this, it is not recommended to run 
    47  performance critical applications that generate a lot of output in the 
    48  foreground over a slow client connection. Instead, users should use the 
    49  `docker logs` command to get access to the logs.
    50  
    51  
    52  ## Override the detach sequence
    53  
    54  If you want, you can configure an override the Docker key sequence for detach.
    55  This is useful if the Docker default sequence conflicts with key sequence you
    56  use for other applications. There are two ways to define your own detach key
    57  sequence, as a per-container override or as a configuration property on  your
    58  entire configuration.
    59  
    60  To override the sequence for an individual container, use the
    61  `--detach-keys="<sequence>"` flag with the `docker attach` command. The format of
    62  the `<sequence>` is either a letter [a-Z], or the `ctrl-` combined with any of
    63  the following:
    64  
    65  * `a-z` (a single lowercase alpha character )
    66  * `@` (at sign)
    67  * `[` (left bracket)
    68  * `\\` (two backward slashes)
    69  *  `_` (underscore)
    70  * `^` (caret)
    71  
    72  These `a`, `ctrl-a`, `X`, or `ctrl-\\` values are all examples of valid key
    73  sequences. To configure a different configuration default key sequence for all
    74  containers, see [**Configuration file** section](cli.md#configuration-files).
    75  
    76  #### Examples
    77  
    78      $ docker run -d --name topdemo ubuntu /usr/bin/top -b
    79      $ docker attach topdemo
    80      top - 02:05:52 up  3:05,  0 users,  load average: 0.01, 0.02, 0.05
    81      Tasks:   1 total,   1 running,   0 sleeping,   0 stopped,   0 zombie
    82      Cpu(s):  0.1%us,  0.2%sy,  0.0%ni, 99.7%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
    83      Mem:    373572k total,   355560k used,    18012k free,    27872k buffers
    84      Swap:   786428k total,        0k used,   786428k free,   221740k cached
    85  
    86      PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
    87       1 root      20   0 17200 1116  912 R    0  0.3   0:00.03 top
    88  
    89       top - 02:05:55 up  3:05,  0 users,  load average: 0.01, 0.02, 0.05
    90       Tasks:   1 total,   1 running,   0 sleeping,   0 stopped,   0 zombie
    91       Cpu(s):  0.0%us,  0.2%sy,  0.0%ni, 99.8%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
    92       Mem:    373572k total,   355244k used,    18328k free,    27872k buffers
    93       Swap:   786428k total,        0k used,   786428k free,   221776k cached
    94  
    95         PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
    96             1 root      20   0 17208 1144  932 R    0  0.3   0:00.03 top
    97  
    98  
    99       top - 02:05:58 up  3:06,  0 users,  load average: 0.01, 0.02, 0.05
   100       Tasks:   1 total,   1 running,   0 sleeping,   0 stopped,   0 zombie
   101       Cpu(s):  0.2%us,  0.3%sy,  0.0%ni, 99.5%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
   102       Mem:    373572k total,   355780k used,    17792k free,    27880k buffers
   103       Swap:   786428k total,        0k used,   786428k free,   221776k cached
   104  
   105       PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
   106            1 root      20   0 17208 1144  932 R    0  0.3   0:00.03 top
   107      ^C$
   108      $ echo $?
   109      0
   110      $ docker ps -a | grep topdemo
   111      7998ac8581f9        ubuntu:14.04        "/usr/bin/top -b"   38 seconds ago      Exited (0) 21 seconds ago                          topdemo
   112  
   113  And in this second example, you can see the exit code returned by the `bash`
   114  process is returned by the `docker attach` command to its caller too:
   115  
   116      $ docker run --name test -d -it debian
   117      275c44472aebd77c926d4527885bb09f2f6db21d878c75f0a1c212c03d3bcfab
   118      $ docker attach test
   119      $$ exit 13
   120      exit
   121      $ echo $?
   122      13
   123      $ docker ps -a | grep test
   124      275c44472aeb        debian:7            "/bin/bash"         26 seconds ago      Exited (13) 17 seconds ago                         test