brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: leave docker attach with Ctrl+P Ctrl+Q, not Ctrl+C

Docker
~/tips/tip-docker-attach-detach-keys

docker attach mc-server

Detach from a container's console without stopping the process inside it.

docker attach connects your terminal to the main process of a running container, which is handy for game servers and other apps with a console. Getting out again is where people go wrong.

docker attach mc-server

Press Ctrl+C and your terminal sends SIGINT to the process in the container, because attach forwards signals by default. For most apps that means a shutdown. The polite way out is the detach sequence Ctrl+P followed by Ctrl+Q, which disconnects your terminal and leaves the process running.

That sequence only works when the container was started with -it, so it has a terminal and an open input. Without those, you can still attach safely with:

docker attach --sig-proxy=false mc-server

Now Ctrl+C only ends your attach session.

If Ctrl+P clashes with something you use, like shell history in an editor running inside the container, pick another sequence with --detach-keys, for example --detach-keys="ctrl-x,x". It also works on docker run and docker exec.

For simply reading output, I would use docker logs -f instead. It cannot send anything to the process, so there is nothing to get wrong.

Further reading: docker container attach

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link