Docker attach Command

Docker attach Command

docker attach : Connects to a running container.

Docker attach Syntax

docker attach [OPTIONS] CONTAINER

To attach the container must be running, can be connected to the same container at the same time to share the screen (similar to the screen command attach).

The official documentation says that you can detach by CTRL-C after attaching, but actually after my test, if the container is currently running bash, CTRL-C is naturally the current line of input, no exit; if the container is currently running processes in the foreground, such as the output of nginx access.log log. CTRL-C will not only result in exiting the container, but also stop. This is not what we want, detach is supposed to be out of the container terminal, but the container is still running. The good thing about attach is that you can bring –sig-proxy=false to ensure that CTRL-D or CTRL-C does not shut down the container.

Docker attach Examples

The container mynginx refers the access log to the standard output and connects to the container to view the access information.

apidemos@apidemos:~$ 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" "-"
Like(0)