How to run Nakama on Raspberry Pi
- Game server
- Authoritative instance of your multiplayer game - the actual game world.
- Meta-game server
- App providing services related to the multiplayer functionality, but not the game itself. For example player profiles, leaderboards, matchmaking, etc.
When developing multiplayer games with Nakama, my first thought was to run it on my latop (alongside Godot engine) and not worry about it. But in production, the meta-game server is not going to be running on the same machine as the game. So I thought I’d adopt this mentality from the very start - no hardcoded localhost
in the game code!
I have a spare Raspberry Pi 🍓 on my shelf, so I thought let’s put the Nakama on there.
Nakama’s docker compose documentation will get you pretty far - you’ll have Nakama up and running on the RPI no problem. One thing I’d note is to grab the docker compose file directly from their GitHub to get the latest version, the one in the docs is outdated. I used the Postgres one - here.
After running docker compose up --detach
, Nakama is running on the Raspberry. But trying to go to the Nakama Console on my laptop shows a blank page!
raspberrypi.local:7351
crypto.randomUUID
is only available in secure context! That means a HTTPS connection. That is ridiculous, I’m not going to bother with HTTPS on my own network. Luckily there is an exception to this rule: http://localhost
is considered secure too!
All we need is a SSH tunnel to the raspberry, routing all traffic to localhost
.
ssh -L 7351:localhost:7351 vojta@raspberrypi.local -N
Now going to localhost:7351
shows the admin console, even though it’s running somewhere else!
Note
The SSH tunnel ONLY routes the 7351 port - the one that serves the Nakama Console. Other ports stay where they are - localhost
will NOT work in game code. There, you have to supply an IP address :)