Skip to content

Instantly share code, notes, and snippets.

@skwashd
Last active January 15, 2022 15:29
Show Gist options
  • Save skwashd/904a16029abd4501e336907e719d426d to your computer and use it in GitHub Desktop.
Save skwashd/904a16029abd4501e336907e719d426d to your computer and use it in GitHub Desktop.
Auto starting minecraft server in a docker container on Ubuntu 16.04

The better way to do this

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.

My old way of doing it

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 ExecStart line 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 with Active: active (running).
  • Run docker ps and look for an entry minecraft in the NAMES column.
  • If you want to double check it all works reboot the server and run docker ps again.
  • Tweet a link to this gist and follow @skwashd on twitter.
[Unit]
Description=Minecraft container
Requires=docker.service
After=docker.service
[Service]
Restart=on-failure
RestartSec=10
ExecStart=/usr/bin/docker run --rm -e EULA=TRUE -e TYPE=BUKKIT -e VERSION=1.9.4 -v /srv/docker/containers/minecraft/data:/data -p 25565:25565 --name mc itzg/minecraft-server
ExecStop=/usr/bin/docker kill mc
[Install]
WantedBy=local.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment