By following default installation of Discourse on Docker, the server manages to autostart upon host machine reboot. As I wish to know more about inner side of Discourse, I wonder how the docker can autostart Discourse image?
There were some serious bugs here in previous versions of Docker, for the record… but yes, current 1.2+ Docker versions do restart containers reliably on boot!
Docker knows what command the container is supposed to be running (I believe it’s
runit?) so it just remembers that and starts it again on boot.
Read up about restart policies
That’s about restarting if the process exits, not if the machine turns off.
That is about both from all I can tell, the restart policy changes corrected the reboot behavior, crash behavior and upgrade behavior.
So the restart mechanism is done by docker, not by discourse image in particular nor by discourse script.
Yes, this is built in to Docker
I still don’t understand. At the moment I have a Discourse installation where it should not run (a different web server is serving redirects currently, it’s part of a migration). I’ve stopped Discourse with
./launcher stop app, and absolutely nothing Discourse-related is running. But a reboot or a
service restart docker promptly starts the Discourse container again. Where does this come from, so I can kill it? The restart policies linked feels like something that should only be in effect for running containers?
Sounds like a docker bug cc @SvenDowideit
Simple workaround is launcher destroy app
The second option is to restart the instance on boot using an init script (sysv init, runit, upstart, systemd, whatever).
Unfortunately you can’t change restart policy of an already started instance, therefore you need the second option to fully control your docker instance.
For example here is an upstart config to run my youtrack container:
description "Youtrack docker container" start on runlevel  and started docker stop on runlevel [!2345] respawn respawn limit 10 5 exec /usr/bin/docker start -a youtrack || /usr/bin/docker run --rm --name youtrack -v /opt/youtrack:/opt/youtrack -p 8000:8000 -h localhost -u youtrack ops/youtrack /opt/youtrack/run
docker wasn’t starting on boot (not sure why), and
systemctl enable docker fixed that. Discourse starts automatically now if the VPS reboots :-]