Error -2 connecting to redis.railway.internal:6379. Name or service not known..
benedwards44
HOBBYOP

a month ago

I'm looking to migrate my first of five Django apps over from Heroku to Railway. It's been a pretty seamless experience right up until this final hurdle!

I'm trying to deploy my worker service and I'm retrieving a build error whereby the worker (and Celery) seems unable to connect to the Redis URL:

[2026-01-22 11:05:15,137: ERROR/MainProcess] consumer: Cannot connect to redis://default:**@redis.railway.internal:6379//: Error -2 connecting to redis.railway.internal:6379. Name or service not known..

I've followed the guide closely here

https://docs.railway.com/guides/django

All variables are set across web and worker services (REDIS_URL in particular), and everything appears to be set up correctly. The Redis database is online and appears to be ready to go. The worker service is attempting to connect on the correct URL and is using the correct username/pass but it just doesn't seem to connect. Everything is in the same region and same project.

I just can't understand why it can't find the service using the REDIS_URL.

Any help would be appreciated!

Solved$10 Bounty

Pinned Solution

darseen
HOBBYTop 5% Contributor

a month ago

celery -A packagebuilder worker -l info --concurrency=3 command is meant to start your application, not build it as far as I know. Because you placed it in the Build Command, Railway is trying to launch your worker process inside the build environment (which has no network access), causing the crash.

Move the command to Start Command in your service settings and it should work.

6 Replies

douefranck
FREE

a month ago

hey i just checked the railway django guide you followed and found something , in step 2 where you add variables it says to set redis_url to ${{Postgres.REDIS_URL}} but that's wrong because postgres is your database not redis. your redis_url variable should be ${{Redis.REDIS_URL}} instead (reference your actual redis service not postgres). also double check that your worker service and redis service are both in the exact same project and same environment on railway because private networking only works within the same project/environment. those are the two most common issues according to the railway docs for this exact error

doue


darseen
HOBBYTop 5% Contributor

a month ago

Private networking is not available during the build phase. If you have code that tries to connect to redis during build it will fail.


benedwards44
HOBBYOP

a month ago

Hi @douefranck, thanks for your response. I also noticed that when reading the doc but had set the correct REDIS_URL against the web and worker variables when setting it up. This autocompletes in the UI as well and I've validated it.

The error even shows it's found the correct REDIS_URL and is attempting to connect to it but it fails.

@darseen This would indeed be an issue as the build is trying to connect to the private URL, but my app is using the same approach as the Django guide as all the Django + Celery templates I've been reviewing:
https://github.com/Antvirf/railway_django_stack
https://github.com/tecladocode/django-celery-starter

So I don't really understand how I'd configure this differently? To be clear it's failing on this command:
celery -A packagebuilder worker -l info --concurrency=3

Whereby my app name is packagebuilder. This is a custom build command as per the docs, and this is what is trying to connect to the private URL.

Lastly, I can confirm everything is in the same project, same environment, same region.


darseen
HOBBYTop 5% Contributor

a month ago

celery -A packagebuilder worker -l info --concurrency=3 command is meant to start your application, not build it as far as I know. Because you placed it in the Build Command, Railway is trying to launch your worker process inside the build environment (which has no network access), causing the crash.

Move the command to Start Command in your service settings and it should work.


benedwards44
HOBBYOP

a month ago

@darseen you're a legend! Thanks for your help. The issue was very much the fact I was running celery -A as a build command and not a start command.

All up and running now! Thanks again, thought I was losing my mind. pray emoji


darseen
HOBBYTop 5% Contributor

a month ago

You're welcome! Glad I was able to help.


Status changed to Solved brody about 1 month ago


Loading...