Detached and interactive mode: -d, -i and -t
Select an icon to see what it is.
Step 6 of 6
Leaving: exit stops it, detach keys do not
Typing exit, or pressing Ctrl-D, ends the shell. The shell is PID 1, so the container stops. To leave a running container without stopping it, press Ctrl-P and then Ctrl-Q, the default detach keys, and reconnect later with docker attach.
PrevNext
State after exit
{"State": {"Status": "exited""ExitCode": 0}}
Try it yourself
Run a shell inside a container, then run one in the background and open a second shell in it.
$ docker run -it --rm alpine sh # type hostname, then exit$ docker run -d --name sleeper alpine sleep 1000$ docker exec -it sleeper sh # type ps, then exit$ docker rm -f sleeper