Docker Installation
Note: The official MegaMek Docker images have Sentry error reporting turned ON. It sends crash reports to the MegaMek team. To turn it off, build your own image (see Building Your Own Image below).
These are basic instructions for getting a dedicated server up and running using a hosting provider. Does NOT require adjusting your own router or firewall settings. These are at a basic to intermediate level. Familiarity with SSH and the shell are imperative! Do NOT use a web based console for this tutorial.
We’ll be using DigitalOcean as a basis for this. They have a large collection of tutorials on setting up a server. They can be used with other providers as well.
For this tutorial, we’ll be using their second-cheapest droplet to setup an instance on which is $6/mo USD as of this writing. This will allow us to dedicate 768M of ram to MegaMek which should be more than enough for most games and scenarios. If you need more, upgrading to the $12/mo USD instance is a few clicks and the settings can be adjusted to give MegaMek 1536M of ram instead. In our testing, that was overkill.
To set up an account, go to DigitalOcean.
If using DigitalOcean, the initial survey can be a bit daunting. Most is for their internal CRM to help them figure out how people are using their services. We’ve suggested people fill in
self hosted game serverin forWhat is the project?(or however it’s phrased).
If unfamiliar with initial server setup, please check out Initial Server Setup with Ubuntu for setting up the initial user that we’ll be using for MegaMek.
After you’ve done the initial server setup, follow along using the created user.
We suggest calling the user
megamek.
Server Requirements (recommended for most)
- Ubuntu 24.04 LTS
- 1 vCPU
- 1GB RAM
- 25G HDD
Before you begin
Make sure you have a non-privileged user created with sudo privileges and you
can login as said user. You do NOT want to run MegaMek as the root user for
security reasons. If not sure how to do this, follow this tutorial -
Initial Server Setup with Ubuntu.
System Updates and Docker
Before we even begin to get MegaMek setup, we need to make sure the server is up to date with all of its patches and Docker is installed. It’s best to log in via the created user vs root for security reasons.
First update all the software with the following command. It’s all in one line to chain 3 commands together.
# step 1
sudo apt update && sudo apt upgrade -y && sudo apt dist-upgrade -y
This will update the software list, upgrade already installed packages, and upgrade the kernel if needed. A reboot is recommended after this but can wait until after everything else has been setup.
For Docker, it’s several steps that are being copied from the official documentation.
# step 2
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
These are a lot of steps, I know. In order, the first command removes any existing install on the current system. On a fresh setup they should not exist but this is precautionary to prevent any conflicts. The next several lines ensures the package cache is current, local certificates (used for ensuring secure communication), and curl (command line tool for getting files and webpages) are installed. The next 3 lines sets ups a place for storing signing keys used to verify packages (don’t want unauthorized packages compromising our systems now), downloads Docker’s public key, and makes it readable by all.
The next line adds a package source, with the signing key, for our server architecture (Intel/Arm) to the package manager so we can easily install and update docker packages. The last 2 lines updates the cache of packages and installs the various Docker utilities.
Once all are installed, run sudo systemctl enable docker to ensure the Docker Engine boots up upon server startup.
Permissions
Once Docker is installed, you need to make sure you can access it without being root. This is simple as
sudo usermod -aG docker <username>
then log out then back in for it to take effect. At this point, run docker ps to see that there are no containers running.
This is just a final test to ensure Docker is up and running.
Getting MegaMek
The MegaMek team publishes official images to the GitHub Container Registry. No account is needed, as the images are public. They work on both Intel/AMD (amd64) and Arm (arm64) servers.
# step 3
docker pull ghcr.io/megamek/megamek:latest
This pulls the newest stable release. Replace the text after the : with the tag you want:
| Tag | What you get |
|---|---|
latest or core |
The newest Core (stable) release |
experimental |
The newest Experimental release |
A version, such as v0.51.01.15 |
That exact release. Every release has its own tag |
Your server and your players must run the same MegaMek version. For a long-running game, use a version tag so the server does not move to a new release before your players do. The list of tags is on the package page.
New images are built within a few hours of each MegaMek release. The current images are also rebuilt every week to pick up Java and Ubuntu security fixes.
Creating and Running the Container
Once the image is pulled, start the server with:
docker run -d --restart unless-stopped -p 2346:2346 -e JAVA_TOOL_OPTIONS=-Xmx768m --name megamek ghcr.io/megamek/megamek:latest
This starts the server, restarts it by itself after a reboot, opens port 2346 to the public, and gives the
container the name megamek so it is easy to update later.
-e JAVA_TOOL_OPTIONS=-Xmx768m lets MegaMek use up to 768M of memory. Without it, Java only uses a quarter of
the server’s memory, which is 256M on a 1GB server. On a 2GB server, use -Xmx1536m instead.
Updating the Container
With the latest, core or experimental tags, updating takes 5 commands and a few seconds.
These pull the newest image, stop the running container, remove it so you start clean, start a new one from the new image, then delete the old image to free up disk space.
docker pull ghcr.io/megamek/megamek:latest
docker stop megamek
docker container rm megamek
docker run -d --restart unless-stopped -p 2346:2346 -e JAVA_TOOL_OPTIONS=-Xmx768m --name megamek ghcr.io/megamek/megamek:latest
docker image prune -f
If you use a version tag, put the new version in both the docker pull and the docker run lines.
Custom User Data on Docker
To use your own maps, meks and other custom files, keep them in a folder on the server and add it to the
docker run command (both when you first start the container and when you update it).
Add -v <path to userdata folder>:/app/userdata to the command. So if you created a customs folder in your
home folder, the command would be:
docker run -d --restart unless-stopped -p 2346:2346 -e JAVA_TOOL_OPTIONS=-Xmx768m -v ~/customs:/app/userdata --name megamek ghcr.io/megamek/megamek:latest
Congratulations! You have your own server setup now using the stock MegaMek package! You can get to it using the IP Address in the control panel using the default port of 2346.
Now, if you haven’t already, you should restart the server to make sure all the patches have applied and that the server will load up on startup.
# step 4
sudo shutdown -r now
This will trigger the shutdown command with the reboot option and to do it now vs scheduling it for later. If using DigitalOcean, in about 1 minute, the server should be back up and running. Log back in and re-run the status command to confirm.
Happy Hunting MekWarrior!
Building Your Own Image
The Dockerfile and build steps are in the megamek-docker-image repository. Building your own lets you turn Sentry off:
git clone https://github.com/MegaMek/megamek-docker-image.git
cd megamek-docker-image
docker build --build-arg MM_VERSION=0.51.01.15 --build-arg SENTRY_ENABLED=false --tag megamek:0.51.01.15 .
Set MM_VERSION to the release you want, without the leading v. Then use megamek:0.51.01.15 in place of
ghcr.io/megamek/megamek:latest in the commands above.