Cannot connect to Redis via private network in Docker build step
budivoogt
PROOP

7 months ago

I know that to connect to Redis with the private networking URL, I must allow IPv4 and IPv6 connections. I'm initiating my Redis client as follows to accommodate this:

export class RedisClient {
    private readonly client: Redis

    constructor(config: RedisConfig) {
        // Pass family: 0 option to enable dual-stack (IPv4 + IPv6) for Railway
        this.client = new Redis(config.url, { family: 0 })
    }

"ioredis": "^5.6.1"

However the following error appears countless times during deployment of my Docker image:

[ioredis] Unhandled error event: Error: getaddrinfo ENOTFOUND redis.railway.internal at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:120:26)

18 Replies

budivoogt
PROOP

7 months ago

1fb7b057-4030-4839-a1f8-68638ed52a4e



budivoogt
PROOP

7 months ago

What could continue to cause this error? Could it be the Railway injected variable is not available during the Docker build step, and only injected upon runtime once deployed?


budivoogt
PROOP

7 months ago

I'm running Redis in the same environment with the Railway template. The REDIS_URL is a reference variable in the main app service.


budivoogt
PROOP

7 months ago

Interestingly, the deployment does succeed and the private networking to the IPv6 URL resolves fine during runtime.


brody
EMPLOYEE

7 months ago

The private network is not available during build


budivoogt
PROOP

7 months ago

I see - so what's the recommended solution here? Using a hardcoded PUBLIC_URL, since there's no way to inject it?


brody
EMPLOYEE

7 months ago

is it possible for your application to simply not use redis during build?


budivoogt
PROOP

7 months ago

I'm using a dependency injection container which also has my database and other clients. So it's initialised there during the build phase. Perhaps I could lazy load it. Do you have any other ideas?


brody
EMPLOYEE

7 months ago

Use the public URL during build (don't hardcode it though) and then use the private URL during runtime


budivoogt
PROOP

7 months ago

I see. Will the public url provided by Railway be available during the Dockerfile build stage though? Or is the var only injected during runtime?


budivoogt
PROOP

7 months ago

And hi Brody! Good to see your name again. I hope you're well 🙂


brody
EMPLOYEE

7 months ago

Are you doing a build with a Dockerfile?


budivoogt
PROOP

7 months ago

Yep! See the gist above.


brody
EMPLOYEE

7 months ago

Then all service variables are going to be available during build as long as you ref them with ARG and then all service variables will be available during runtime automatically.


budivoogt
PROOP

7 months ago

Okay excellent so I can simply reference the public url during build and it'll be injected.


budivoogt
PROOP

7 months ago

Cool I will give that a try.


brody
EMPLOYEE

7 months ago

Sounds good!


Loading...