Docker attach Command
docker attach : Attach to a running container.
Syntax
docker attach [OPTIONS] CONTAINER
The container to attach to must be running. Multiple connections to the same container can be made to share the screen (similar to the screen
command's attach feature).
According to the official documentation, detaching can be done with CTRL-C, but in my tests, if the container is running bash, CTRL-C is simply input for the current line and does not exit; if the container is running a foreground process, such as outputting nginx access logs, CTRL-C not only exits the container but also stops it. This is not what we want; the intention of detach should be to leave the container terminal while keeping the container running. Fortunately, the --sig-proxy=false
option can be added to ensure that CTRL-D or CTRL-C does not close the container.
Example
The container mynginx
directs access logs to standard output, attach to the container to view access information.
tutorialpro@tutorialpro:~$ docker attach --sig-proxy=false mynginx
192.168.239.1 - - [10/Jul/2016:16:54:26 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36" "-"