sleep infinity in docker-compose#

Say you have a compose file like this:

version: '3.7'

services:

  reloader:
    build: reloader/
    command: ["sleep", "infinity"]

Then you run

docker-compose up -d
docker-compose restart

… and you wait for what seems like forever when it’s actually a few seconds, but it really is forever considering that all you do is send a SIGTERM to sleep.

Then you ask yourself: „Why does this take so long?“ and as so many times before stackoverflow has the answer: The init process and the kernel’s reluctancy to send TERM to PID 1.

All you need is this:

version: '3.7'

services:

  reloader:
    build: reloader/
    command: ["sleep", "infinity"]
    init: true  # to handle SIGTERM correctly