Environment variables not available in containerized NestJS app.
Anonymous
FREEOP

a month ago

Hello, I'm trying to deploy a set of containers to railway. The problem I'm facing is: the variables I set in the services's Variables tab does not seem to be available at runtime, thus crashing my application.

I did click deploy (this was the culprit in similar threads).

$10 Bounty

6 Replies

Railway
BOT

a month ago

This thread has been opened as a bounty so the community can help solve it.

Status changed to Open Railway 29 days ago


If you're using a Dockerfile, you'd need to add ARG statements into it.

Also, does logging process.env.<VARIABLE> just return undefined?


0x5b62656e5d

If you're using a Dockerfile, you'd need to add `ARG` statements into it. Also, does logging `process.env.<VARIABLE>` just return `undefined`?

Anonymous
FREEOP

a month ago

It does return undefined. And I was under the impression railway added the environment variables in the docker command.

I'll look into both ARG and ENV statement.


If your env variables aren't available at runtime, ARG won't help, because it makes your variables accessible during the build process only. You should use ARG if env variables are baked into the application at build time (like vite), so it's worth trying. You can read more about it here: https://docs.railway.com/builds/dockerfiles#using-variables-at-build-time


Anonymous
FREEOP

a month ago

Yes, I tried using ARG and ENV, neither works. I'll try to rollback to a single stage Dockerfile which did work in another environment.


Yes, I tried using ARG and ENV, neither works. I'll try to rollback to a single stage Dockerfile which did work in another environment.

If a single stage Dockerfile works without an issue, I suggest you check if you are using the env variables in the stages that require them specifically.


Anonymous
FREEOP

a month ago

It did work. And I'm not using them in the build stages since the error happens at deploy.

I will check exactly what's different later. Thank you all.

Should I keep this open until I figure out what was causing this problem?


Welcome!

Sign in to your Railway account to join the conversation.

Loading...