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: --stop-signal chooses which signal docker stop sends first

Docker
~/tips/tip-docker-stop-signal

docker run -d --stop-signal=SIGQUIT <image>

Sets the signal docker stop sends first, and shows how the grace period before SIGKILL works.

docker stop sends a signal, waits, and only then kills the container. You can choose which signal it sends.

The Docker docs say the main process receives SIGTERM first and SIGKILL after a grace period. The first signal can be changed with the STOPSIGNAL instruction in the Dockerfile or with --stop-signal when you create the container:

docker run -d --stop-signal=SIGQUIT <image>

The value is a signal name in the format SIG<NAME>, or an unsigned number that matches a position in the kernel’s syscall table. Some programs treat a signal other than SIGTERM as the polite way to finish, and this is where you tell Docker about it. If nothing is configured, SIGTERM is used.

The grace period is set separately. For one stop you pass a timeout in seconds:

docker stop --timeout 30 <container>

Without a configured default, the daemon decides: 10 seconds for Linux containers and 30 for Windows containers. For a container that is created with a different default, use --stop-timeout at creation. The docs add that -1 removes the timeout, so Docker waits as long as the process needs. A stuck process then holds your command for good, so I would not use it casually.

The stop signal belongs to the container’s configuration. Changing it means creating the container again.

Further reading: Docker docs: docker container stop, Docker docs: docker container run

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