5 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)
0 Replies
5 months ago
1fb7b057-4030-4839-a1f8-68638ed52a4e
5 months ago
This is my Dockerfile: https://gist.github.com/budivoogt/d750e8c2b6ef24748446899b094f3cdb
5 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?
5 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.
5 months ago
Interestingly, the deployment does succeed and the private networking to the IPv6 URL resolves fine during runtime.
5 months ago
The private network is not available during build
5 months ago
I see - so what's the recommended solution here? Using a hardcoded PUBLIC_URL, since there's no way to inject it?
5 months ago
is it possible for your application to simply not use redis during build?
5 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?
5 months ago
Use the public URL during build (don't hardcode it though) and then use the private URL during runtime
4 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?
4 months ago
And hi Brody! Good to see your name again. I hope you're well 🙂
4 months ago
Are you doing a build with a Dockerfile?
4 months ago
Yep! See the gist above.
4 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.
4 months ago
Okay excellent so I can simply reference the public url during build and it'll be injected.
4 months ago
Cool I will give that a try.
4 months ago
Sounds good!