During a twitter conversation with itzg, he suggested that I use [docker's built in --restart="unless-stopped" runtime flag] (https://gist.github.com/itzg/36e59186f6195a445f1f1fa2b0087ea9). That worked a treat and means I don't need to maintain an extra service.
This is only retained for historic record. Don't follow these steps.
If you want to run a minecraft server in a docker container on Ubuntu 16.04 and have it automatically start at boot, follow these steps:
- Install Ubuntu 16.04. I have not tested these steps any other version of Linux.
- Install docker and make sure it it is working properly.
- Follow itzg's minecraft dockerfile setup guide to start the container for the first time.
- Copy the minecraft.service file below to /lib/systemd/system/minecraft.service.
- Tweak any of the runtime options in the
ExecStartline of the file to suit your needs (yes, you need to read itzg's README!). - Enable the service by running
sudo systemctl enable minecraft. - Restart the service to make sure it works by running
sudo systemctl restart minecraft.service. - Confirm that the service restarted by running
sudo systemctl status minecraft.service. You should see a that starts withActive: active (running). - Run
docker psand look for an entryminecraftin theNAMEScolumn. - If you want to double check it all works reboot the server and run
docker psagain. - Tweet a link to this gist and follow @skwashd on twitter.