You can use the --detach-keys
option when you run docker attach
to override the default CTRL+P, CTRL + Q sequence (that doesn't always work).
For example, when you run docker attach --detach-keys="ctrl-a" test
and you press CTRL+A you will exit the container, without killing it.
Other examples:
docker attach --detach-keys="ctrl-a,x" test
- press CTRL+A
and then X
to exit
docker attach --detach-keys="a,b,c" test
- press A
, then B
, then C
to exit
Extract from the official documentation:
If you want, you can configure an override the Docker key sequence for detach. This is useful if the Docker default sequence conflicts with key sequence you use for other applications. There are two ways to define your own detach key sequence, as a per-container override or as a configuration property on your entire configuration.
To override the sequence for an individual container, use the --detach-keys="<sequence>"
flag with the docker attach command. The format of the <sequence>
is either a letter [a-Z]
, or the ctrl-
combined with any of the following:
- a-z (a single lowercase alpha character )
- @ (at sign)
- [ (left bracket)
- \ (two backward slashes)
- _ (underscore)
- ^ (caret)
These a
, ctrl-a
, X
, or ctrl-\\
values are all examples of valid key sequences. To configure a different configuration default key sequence for all containers, see Configuration file section.
Note: This works since docker version 1.10+ (at the time of this answer, the current version is 18.03)