Issue with Flask Deployment
Hello, here is my project id: e8d46baa-5de4-495e-bc2e-a8a2b37ed2b0. I am trying to deploy my flask/redis application to railway so that one server is running where 1 port is running the flask api part and another part which is running the redis part. I believe I got the redis part on railway to work, as I can see all my data, but for some reason the flask deployment isnt working as expected.
In my main.py, I have this code:
However, when I run the deployment, I see this in the deploy logs:
For some reason, it's running locally instead of the railway url and it gives this notification/popup above the logs saying "Looks like your app is listening on 127.0.0.1. You may need to listen on 0.0.0.0 instead." even though I am listening on 0.0.0.0. I can provide more of what's in my main.py if needed.
I'm not sure what I am doing wrong so would really appreciate it if someone could take a look. Much appreciated!
25 Replies
Project ID:
e8d46baa-5de4-495e-bc2e-a8a2b37ed2b0
It’s only possible to expose one port per service on Railway
You should put your redis in a different service
And judging by your logs, it does seem like something is running on 127.0.0.1. Once you split the services out it’ll be easier to debug
you should also be using gunicorn
This is a development server. Do not use it
So there's no way to run redis as a subprocess under the main flask process on a separate port?
I have a function that starts the redis server:
and I call that function in ` but it doesn't seem to be even running anything in if name = main.
When I deploy to railway, I get this error:
you will want to use the redis plugin railway provides
The port for your flask server should also be
os.getenv(“PORT”)
not RAILWAY_PORT
Thanks that fixed it. Last question: is there anyway to change the value of REDIS_PASSWORD? I hard coded the value in my main.py file instead of using .env variables and accidently pushed to github (its in a private repo so its fine for now).
you can regenerate your redis password in the redis plugin's settings
Really?
yes!
I don’t use redis, so I had no idea
I don’t like redis
you can do it in any database railway provides
Never looked into the settings honestly.
I just create, use, and tear down when I’m done. But good to know
ah got it, I was looking in the connect section instead of settings. thanks
please make sure you are using variable references
not a .env file
like add the variables directly on the railway dashboard?
via variable references
https://docs.railway.app/develop/variables#reference-variables
ah ok
what's wrong with using a .env file?
storing credentials for a public facing database in plaintext is not a good idea in my opinion
keep all secrets in the railway service, and then use the railway cli with
railway run <the command you normally use to start your app>
this way your app has access to the railway service variables without you ever having to copy your secrets to a .env filegot it
wow that was much easier than i expected, thx @Brody
sanity check: show me a screenshot of your service variables?
looks good to me
and now you dont have to put secrets in plaintext! pretty neat right?
I have another question. I am trying to use the RediSearch module (https://redis.io/docs/stack/search/) to perform a query against the redis storage. However, when I run my code, I get this error:
in the railway api console which seems to occur when the redisearch library is not properly installed. I have RediSearch in my requirements.txt file, so any help would be appreciated.
the redis database doesn't have the redisearch module installed, this has nothing to do with whats in your requirements.txt.
you cant install modules yourself so if you need rediseach you will have to use a different database host