Unable to build server with go runtim (Nakama v1.41)

Greetings,

I’m trying to add some go modules to my server, but I am unable to get it build. I’ve tried following the instructions in the docs. It say go.mod requires go >= 1.25.1 and that I am currently running go 1.22.4. But I am, in fact, running go1.25.1.

Thanks for any assistance.

DOCKERFILE

FROM heroiclabs/nakama-pluginbuilder:3.30.0 AS builder
ENV GO111MODULE onENV CGO_ENABLED 1
WORKDIR /backendCOPY . .
RUN go build --trimpath --buildmode=plugin -o ./backend.so
FROM heroiclabs/nakama:3.30.0
COPY --from=builder /backend/backend.so /nakama/data/modulesCOPY --from=builder /backend/local.yml /nakama/data/COPY --from=builder /backend/*.json /nakama/data/modules

docker-compose.yml

version: “3”

services:

cockroachdb:

image: cockroachdb/cockroach:latest-v23.1

command: start-single-node --insecure --store=attrs=ssd,path=/var/lib/cockroach/

restart: "no"

volumes:

  - data:/var/lib/cockroach

expose:

  - "8080"

  - "26257"

ports:

  - "26257:26257"

  - "8080:8080"

healthcheck:

  test: \["CMD", "curl", "-f", "http://localhost:8080/health?ready=1"\]

  interval: 3s

  timeout: 3s

  retries: 5

nakama:

build: .

entrypoint:

  - "/bin/sh"

  - "-ecx"

  - >

    /nakama/nakama migrate up --database.address root@cockroachdb:26257 &&

    exec /nakama/nakama --name nakama1 --database.address root@cockroachdb:26257 --logger.level DEBUG --session.token_expiry_sec 7200 --metrics.prometheus_port 9100        

restart: "no"

links:

  - "cockroachdb:db"

depends_on:

  cockroachdb:

    condition: service_healthy

  prometheus:

    condition: service_started

volumes:

  - ./:/nakama/data

expose:

  - "7349"

  - "7350"

  - "7351"

  - "9100"

ports:

  - "7349:7349"

  - "7350:7350"

  - "7351:7351"

healthcheck:

  test: \["CMD", "/nakama/nakama", "healthcheck"\]

  interval: 10s

  timeout: 5s

  retries: 5

prometheus:

image: prom/prometheus

entrypoint: /bin/sh -c

command: |

  'sh -s <<EOF

    cat > ./prometheus.yml <<EON

  global:

    scrape_interval:     15s

    evaluation_interval: 15s

  scrape_configs:

    - job_name: prometheus

      static_configs:

      - targets: \['localhost:9090'\]

    - job_name: nakama

      metrics_path: /

      static_configs:

      - targets: \['nakama:9100'\]

  EON

  prometheus --config.file=./prometheus.yml

  EOF'      

ports:

  - "9090:9090"

volumes:

data:

go.mod

module example.com/go-project

go 1.25.1

require (
GitHub - heroiclabs/nakama-common: The runtime framework for Nakama server. v1.41.0 // indirect
protobuf module - google.golang.org/protobuf - Go Packages v1.36.8 // indirect
)

1 Like

Hi @Mehoo462,

The logs output and pasted Dockerfile doesn’t seem to have matching Nakama versions.
This also looks like a mistake in your Dockerfile: WORKDIR /backendCOPY . ., please, make sure you’re pasting the errors that you get with the same files you’ve copied.

Your go.mod clearly states that you’re requiring go 1.25.1 in your plugin, but Nakama 3.30.0 requires go 1.24.5. These need to match between Nakama and your plugin code, and could be what’s causing the error.

Hi Simon,

Thanks for your reply. After I wrote, I did notice that go.mod required go1.25.1. When I dropped this down to 1.24.5 I was able to get it to build. I followed the instructions in the docs to generate this file. So I was surprised to run into this error. Where can I see in the docs which version of Go different versions of Nakama require?

Now the server builds, but it’s not actually detecting any of my Go modules. I’ll keep looking into this. I’ve gotten go moduels to work in a very old build. This is the first time I’m trying to use go modules and lua modules on the same server. That should work, right?

It looks like the /backendCOPY . . thing was a copy/paste error. There should be a newline between WORKDIR /backend and COPY . .

FROM heroiclabs/nakama-pluginbuilder:3.30.0 AS builder

ENV GO111MODULE on
ENV CGO_ENABLED 1

WORKDIR /backend
COPY . .

RUN go build --trimpath --buildmode=plugin -o ./backend.so

FROM heroiclabs/nakama:3.30.0

COPY --from=builder /backend/backend.so /nakama/data/modules
COPY --from=builder /backend/local.yml /nakama/data/
COPY --from=builder /backend/*.json /nakama/data/modules

Yes, you can use both Lua and Go modules.

I think you’re missing a COPY statement for your lua files in the Dockerfile.

If you’d like to use a local.yml config file instead of command line args, you should pass the path via the --config flag:

exec /nakama/nakama --config /nakama/data/local.yml --database.address root@cockroachdb:26257 -- --logger.level DEBUG --session.token_expiry_sec 7200 --metrics.prometheus_port 9100

I think you may also need to add the following config in the local.yml file:

data_dir: "./data"

I’m build locally using docker. So I use docker composer up -–build

I do have successful build running on Nakama 3.15.0. I’m trying make a fresh start with Nakama 3.30.0 by following the examples in the docs, and I can’t get it to recognize anything i put in main.go

I’m just trying to copy from the guide here:

It actually is finding my Lua modules because they are just in a module folder under the main project. So copy . . is getting them I think? Either way, the lua modules are working fine.

The problem is it’s not finding my GO modules. I know it’s reading func initModule() from main.go because if i put junk in that function the build fails.

Yet i don’t see any of my logger.Info(“helloworld”) statements, no coinfirmation that my sample RPC was registered, and it’s not appearing on the server.

go.main

package main

import (

“context”

“database/sql”

“time”

github.com/heroiclabs/nakama-common/runtime”

)

func initModule(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, initializer runtime.Initializer) error {

initStart := time.Now()

logger.Info(“helloWord”)

err := initializer.RegisterRpc(“healthCheck”, RpcHealthcheck)

if err != nil {

return err

}

logger.Info(“Module loaded in %dms”, time.Since(initStart).Milliseconds())

return nil

}

Okay, i think i figured out what was going on here.

The example docker-compose.yml in the Go Runtime getting started guide uses Postgres. I want to use Cockroach. So I took docker-compose.yml for Cockraoch from the main server Getting Started Guide.

The both the postgres and cockroach yml files on the Main Getting Started Guide contains the following lines on 37-38:

    volumes:
      - ./:/nakama/data

These lines are not present in the yml example in the Go Runtime setup page.

I removed those lines, and I was able to regress the error to a complaint about modules being built with the wrong verion of golang/protobuf. I ultimately came to realize there is no way to build Go Modules with Nakama v1.41.0. Once I reverted to Nakama v1.40.0 everything was fine.

Is it possible to clear this up in the docs? I feel like I made some reasonable choices, but the root cause was VERY confusing and cost me a few days.

Suggest three things:

  1. Clarifying which version of Go are required for which version of Nakama. go get ``github.com/heroiclabs/nakama-common/runtime pulls Nakama 1.41.0 which says it supports Go 1.25.0. But the latest common version listed is 3.30.0 for 1.40. So when I vendor the latest version, go.mod and modules.txt require 1.25.0. But when I try to build with Common vesrion 3.30.0 in my dockerfile, it says go1.24.5 is required. So I have to manaully modify go.mod and modules.txt from that Nakama1.41.0 automatically creates? I’m not sure how I’m supposed to glean this from the docs.

    Furthermore, if I manually change the required version of go.mod and modules.txt back to 1.24.5, the build fails say my modules are built with a different version of golang/protobuf… which I pulled from github with Nakama1.41.0. So I’m actually not clear on how you’re supposed to build Nakama1.41.0 on Common Version 3.30? They seem to depend on different versions of GO.

    I was unable to get Nakama1.41.0 to build in the end. I could only make this work go get ``github.com/heroiclabs/nakama-common/runtime@v1.40.0

  2. Either, provide a docker-compose.yml for cockraoch in the Go Runtime docs. OR Calling attention to the way the docker-compose for Go Runtime is different from the default example in the Getting started guide. Preferably both.

  3. Perhaps include the the modules folder in the dockerfile example here so that other runtimes will work as well? You are right. once i got go working, I did need to add COPY --from=builder /backend/modules/ /nakama/data/modules to my dockerfile to get my LUA modules.

Thanks!

Hi @Mehoo462,

Thank you for your feedback, we’ve taken note.

Best.

Thanks! I edited my previous post with a few more details.

I noticed in the other thread, that you are using Nakama 3.31.0, which appears to correpond to release v1.41.0. The latest common version listed in the table in the docks is 3.30.0 corresponding to v1.40.0.

I noticed this morning, that a new release for v1.42.0 came out. But that does not correspond to common version 3.32.0.

Pulling v1.42.0 from the default go get command, and running go mod vendor, then building with 3.31.0 as the common version in the Dockerfile gives this error:

test-nakama-1 | {“level”:“fatal”,“ts”:“2025-09-16T16:52:28.257Z”,“caller”:“main.go:204”,“msg”:“Failed initializing runtime modules”,“error”:“plugin.Open("/nakama/data/modules/backend"): plugin was built with a different version of package ``github.com/heroiclabs/nakama-common/api”``}

So I’m not able to find any way to build a Go Runtime on the latest release of Nakama.

Currently the steps to build a go runtime on the latest possible version of Nakama are

go mod init example.com/go-project

go get github.com/heroiclabs/nakama-common/runtime@v1.41.0

If you’re running the latest version of go (current 1.25.1), modify go.mod to ensure you’re requiring go1.25.0 .

Modify the sample dockerfile provided to use common version 3.31.0.

I’m sorry, but I don’t see any way a user could know to make those deviations from the documented procedure without being in direct contact with you.

Nakama v3.32.0 and nakama-common v1.42.0 were just released not even an hour ago and must be used together.

Nakama depends on nakama-common and so each release is tied to a specific version, if you use these two together it’ll work.

I understand the docs aren’t very clear around these details, they presume some knowledge of how the Go toolchain and dependencies works. We’ll definitely make this clearer in the future.

1 Like

ah! docker compose up is now fetching 3.32.0 correctly. I must have tried to build right at the moment when they were desynced.

Thanks again for you all your support. The responsiveness on this forum has been fantastic and extroardinarily helpful. Much appreciated.