How to set environment variables when deploying using CLI
I know that it is not possible to set environment variables via "railway variables set" when deploying using the CLI. So, I would like to know how to automatically set the environment variables from the ".env" file when I prepare the ".env" file and the "Dockerfile" and deploy them.
The contents of "Dockerfile" are as follows.
FROM python:3.11
WORKDIR /bot
COPY requirements.txt /bot/
RUN pip install -r requirements.txt
COPY . /bot
CMD python main.py
8 Replies
Project ID:
N/A
N/A
Projects might have multiple environments, by default the CLI points to the production environment. If you'd like to use a different set of environment variables and a different deployment environment you can change the setting by:
⚠️ experimental feature
theres no automatic way, the current version of the cli has no provisions for settings variables in any manner.
you will want to copy the contents of the .env file into the raw variable editor, this way you wont need to keep a local copy of the production .env file (bad practice)
Thank you for your answer. I hope that a function that can set environment variables on the CLI will be implemented (restored).
you might not need it for your use case
When I tried running the V2 railway, "railway init" read the ".env" file and added the environment variables to "Shared Variables". Then, after deploying, I was able to import all environment variables by selecting "Shared Variables" from the "Variables" settings.
V3 could not do the above. Personally, I prefer the V2 specification, but why can't I do the above with V3?
It just simply wasn't implemented, the reason for leaving it out I'm not sure, but like I said, after copying the the variables over once manually you won't need to set any more from the CLI because you can set them in the UI