github.com/tompao/docker@v1.9.1/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        --help=false        Print usage
    18        --no-stdin=false    Do not attach STDIN
    19        --sig-proxy=true    Proxy all received signals to the process
    20  
    21  The `docker attach` command allows you to attach to a running container using
    22  the container's ID or name, either to view its ongoing output or to control it
    23  interactively. You can attach to the same contained process multiple times
    24  simultaneously, screen sharing style, or quickly view the progress of your
    25  detached  process.
    26  
    27  You can detach from the container and leave it running with `CTRL-p CTRL-q`
    28  (for a quiet exit) or with `CTRL-c` if `--sig-proxy` is false.
    29  
    30  If `--sig-proxy` is true (the default),`CTRL-c` sends a `SIGINT` to the
    31  container.
    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  #### Examples
    43  
    44      $ docker run -d --name topdemo ubuntu /usr/bin/top -b
    45      $ docker attach topdemo
    46      top - 02:05:52 up  3:05,  0 users,  load average: 0.01, 0.02, 0.05
    47      Tasks:   1 total,   1 running,   0 sleeping,   0 stopped,   0 zombie
    48      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
    49      Mem:    373572k total,   355560k used,    18012k free,    27872k buffers
    50      Swap:   786428k total,        0k used,   786428k free,   221740k cached
    51  
    52      PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
    53       1 root      20   0 17200 1116  912 R    0  0.3   0:00.03 top
    54  
    55       top - 02:05:55 up  3:05,  0 users,  load average: 0.01, 0.02, 0.05
    56       Tasks:   1 total,   1 running,   0 sleeping,   0 stopped,   0 zombie
    57       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
    58       Mem:    373572k total,   355244k used,    18328k free,    27872k buffers
    59       Swap:   786428k total,        0k used,   786428k free,   221776k cached
    60  
    61         PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
    62             1 root      20   0 17208 1144  932 R    0  0.3   0:00.03 top
    63  
    64  
    65       top - 02:05:58 up  3:06,  0 users,  load average: 0.01, 0.02, 0.05
    66       Tasks:   1 total,   1 running,   0 sleeping,   0 stopped,   0 zombie
    67       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
    68       Mem:    373572k total,   355780k used,    17792k free,    27880k buffers
    69       Swap:   786428k total,        0k used,   786428k free,   221776k cached
    70  
    71       PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
    72            1 root      20   0 17208 1144  932 R    0  0.3   0:00.03 top
    73      ^C$
    74      $ echo $?
    75      0
    76      $ docker ps -a | grep topdemo
    77      7998ac8581f9        ubuntu:14.04        "/usr/bin/top -b"   38 seconds ago      Exited (0) 21 seconds ago                          topdemo
    78  
    79  And in this second example, you can see the exit code returned by the `bash`
    80  process is returned by the `docker attach` command to its caller too:
    81  
    82      $ docker run --name test -d -it debian
    83      275c44472aebd77c926d4527885bb09f2f6db21d878c75f0a1c212c03d3bcfab
    84      $ docker attach test
    85      $$ exit 13
    86      exit
    87      $ echo $?
    88      13
    89      $ docker ps -a | grep test
    90      275c44472aeb        debian:7            "/bin/bash"         26 seconds ago      Exited (13) 17 seconds ago                         test