Correct way to detach from a container without stopping it

In Docker 1.1.2 (latest), what's the correct way to detach from a container without stopping it?

So for example, if I try:

  • docker run -i -t foo /bin/bash or
  • docker attach foo (for already running container)

both of which get me to a terminal in the container, how do I exit the container's terminal without stopping it?

exit and CTR+C both stop the container.


Update: As mentioned in below answers Ctrl+p, Ctrl+q will now turn interactive mode into daemon mode.

Well Ctrl+C (or Ctrl+\) should detach you from the container but it will kill the container because your main process is a bash.

A little lesson about docker. The container is not a real full functional OS. When you run a container the process you launch take the PID 1 and assume init power. So when that process is terminated the daemon stop the container until a new process is launched (via docker start) (More explanation on the matter

If you want a container that run in detached mode all the time, i suggest you use

docker run -d foo

With an ssh server on the container. (easiest way is to follow the dockerizing openssh tutorial

Or you can just relaunch your container via

docker start foo

(it will be detached by default)