Docker Deployment with Environment Variables and Custom Entrypoint (Nakama Server)

eduardomoroni
PRO

4 months ago

I'm trying to migrate my Nakama Server (https://github.com/heroiclabs/nakama)
From Fly.io to Railway.

I read at https://docs.railway.com/guides/start-command

When specifying a start command, the behavior depends on the type of deployment: Dockerfile / Image: the start command overrides the image's ENTRYPOINT in exec form.

  • If you need to use environment variables in the start command for services deployed from a Dockerfile or image you will need to wrap your command in a shell -

    /bin/sh -c "exec python main.py --port $PORT"

    This is because commands ran in exec form do not support variable expansion.

    But unfortunately I'm not able to succesfully override docker's entrypoint while passing env vars to the docker

    Here's the start command
    /bin/sh -ecx "/nakama/nakama --config /nakama/data/local.yml --database.address $DATABASE_URL"

  • Can anybody help me figure out what I'm missing?

    ---
    Here's a sample docker-compose file: https://github.com/heroiclabs/nakama/blob/master/docker-compose-postgres.yml
    And
    the fly.toml for reference:

[experimental]

entrypoint = [

"/bin/sh", "-ecx",

"/nakama/nakama migrate up --database.address $DATABASE_URL && exec /nakama/nakama --name $FLY_MACHINE_ID --config /nakama/data/local.yml --database.address $DATABASE_URL --console.username $CONSOLE_USERNAME --console.password $CONSOLE_PASSWORD --console.signing_key $CONSOLE_SIGNING_KEY --session.refresh_encryption_key $SESSION_REFRESH_ENCRYPTION_KEY --session.encryption_key $SESSION_ENCRYPTION_KEY"

]

$RUNTIME_HTTP_KEY

[build]

dockerfile = "Dockerfile"

[[services]]

internal_port = 7350

protocol = "tcp"

[[services.ports]]

handlers = ["http", "tls"]

start_port = 7350

end_port = 7350

[[services]]

internal_port = 7351

protocol = "tcp"

processes = ['app']

[[services.ports]]

handlers = ["http", "tls"]

start_port = 7351

end_port = 7351

[metrics]

port = 9090

path = "/"

Solved

3 Replies

4 months ago

Hmmm- a simple fix, did you try adding ARGS for the variable references that you need?


Status changed to Awaiting User Response railway[bot] 4 months ago


eduardomoroni
PRO

4 months ago

thanks I fixed it.

{ "$schema": "https://railway.com/railway.schema.json", "build": { "builder": "DOCKERFILE", "dockerfilePath": "apps/nakama/Dockerfile" }, "deploy": { "preDeployCommand": [ "/bin/sh -ecx \"/nakama/nakama migrate up --database.address $DATABASE_URL\"" ], "startCommand": "/bin/sh -ecx \"exec /nakama/nakama --config /nakama/data/local.yml --database.address $DATABASE_URL --console.username $CONSOLE_USERNAME --console.password $CONSOLE_PASSWORD --console.signing_key $CONSOLE_SIGNING_KEY --session.refresh_encryption_key $SESSION_REFRESH_ENCRYPTION_KEY --session.encryption_key $SESSION_ENCRYPTION_KEY\"", "restartPolicyType": "ALWAYS" } }


Status changed to Awaiting Railway Response railway[bot] 4 months ago


4 months ago

Wonderful thanks for raising an issue. Happy shipping!


Status changed to Awaiting User Response railway[bot] 4 months ago


Status changed to Solved angelo 4 months ago