English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Docker attach command

Docker Command Summary

docker attach :Connect to a running container.

Syntax

docker attach [OPTIONS] CONTAINER

The container to be attached must be running, and you can connect to the same container simultaneously to share the screen (similar to the screen command's attach).

The official documentation states that after attach, you can use CTRL-C to detach, but actually after my test, if the container is currently running bash, CTRL-C is naturally the input of the current line, without exiting; if the container is currently running a foreground process, such as outputting the nginx access.log log, CTRL-C not only causes the container to exit but also stops it. This is not what we want. The detach should logically mean to detach from the container terminal, but the container still runs. Fortunately, attach can be--sig-proxy=false to ensure CTRL-D or CTRL-C will not close the container.

Online Example

The container mynginx will direct the access log to standard output and connect to the container to view access information.

w3codebox@w3codebox:~$ 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" "-"

Docker Command Summary