I have a small fastify app that connects to an external Redis server.
I am using the fastify-redis npm package (which uses ioredis under the hood).
fastify-redis is connecting using rediss:// format
REDIS_URL='rediss://:[email protected]:6380'
const Fastify = require('fastify')
const fastifyRedis = require('@fastify/redis')
fastify = Fastify({ logger: true, pluginTimeout: 50000 })
fastify.register(fastifyRedis, {
url: process.env.REDIS_URL,
enableAutoPipelining: true,
})
This all works fine run locally using npm start.
When I dockerise it, though, I get an error, which looks like it is caused by not being able to connect to the Redis instance
redisutils_1 | > node index.js
redisutils_1 |
redisutils_1 | /usr/src/node_modules/ioredis/built/redis/event_handler.js:175
redisutils_1 | self.flushQueue(new errors_1.MaxRetriesPerRequestError(maxRetriesPerRequest));
redisutils_1 | ^
redisutils_1 |
redisutils_1 | MaxRetriesPerRequestError: Reached the max retries per request limit (which is 20). Refer to "maxRetriesPerRequest" option for details.
redisutils_1 | at Socket.<anonymous> (/usr/src/node_modules/ioredis/built/redis/event_handler.js:175:37)
redisutils_1 | at Object.onceWrapper (node:events:628:26)
redisutils_1 | at Socket.emit (node:events:513:28)
redisutils_1 | at TCP.<anonymous> (node:net:313:12)
redisutils_1 |
redisutils_1 | Node.js v18.9.0
What have I missed?
2
Answers
I discovered the issue.
2 things.
Namely
you mostly will need to run your container with
--network host
as your container runnning inside private network and can’t reach your network to communicate with any external services.