s6 Quick Container Exit - blitterated/docker-dev-env-s6 GitHub Wiki

Here's how to exit quickly from an s6-overlay managed docker container if you really really don't care about how the managed processes die, and you don't want to override S6_SERVICES_GRACETIME and S6_KILL_GRACETIME.

This is great if you're developing an image, especially if you're iterating through containers and running with the --rm switch already.

s6 Shutdowm Command

This has the same grace periods as exit in Docker, about 6 seconds by default.

s6-linux-init-shutdown -p now

The original s6-svscanctl -q -b

This doesn't work with s6-rc based systems scandir, /var/run/s6/services because there is no longer a services directory in /var/run/s6.

s6-svscanctl -q -b `/var/run/s6/services`

Under the old services.d style, the scandir was /var/run/s6/services. You could see that by looking at s6-svscan with ps.

root@0bc9b0b5d629:/~# ps q 1
  PID TTY      STAT   TIME COMMAND
    1 ?        Ss     0:00 s6-svscan -t0 /var/run/s6/services

The new s6-svscanctl -q -b

Under the s6-rc style, it looks like the scandir is now /run/service

root@7289cb8a8b06:/~# ps q 1
  PID TTY      STAT   TIME COMMAND
    1 ?        Ss     0:00 /package/admin/s6/command/s6-svscan -d4 -- /run/service

So we should be able to use that path to shut down all s6 managed services, and then quickly exit docker.

s6-svscanctl -q -b /run/service && exit

Turns out it pops up a quick "fatal" error, and then successfully exits the container.

root@97fe659fe54e:/~# s6-svscanctl -q -b /run/service && exit
exit
s6-linux-init-hpr: fatal: unable to talk to shutdownd: Operation not permitted
λ (master) ~/src/blitterated/xyz:

It works when you combine switches together, too.

s6-svscanctl -qb /run/service && exit

Resources