I tried having a Sveltekit app with redis running on docker-compose (which was running just fine on the host machine without docker)
I tried with this docker-compose.yml
:
version: '3.8'
services:
app:
build: .
ports:
- "3000:3000"
depends_on:
- redis
redis:
image: redis:latest
ports:
- "6379:6379"
command: ["redis-server", "--requirepass", "tj9Z47LRLRzbShNQxFnpPvd5bLpzqZky"]
And this Dockerfile
:
FROM node:22
WORKDIR /app
COPY package*.json .
RUN npm install
COPY . .
RUN npm run build
EXPOSE 3000
CMD [ "node", "build" ]
And got this error:
Error: connect ECONNREFUSED 127.0.0.1:6379
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 6379
}
Just for context, this is src/lib/redis.ts
:
import { createClient } from "redis";
import { REDIS_HOST, REDIS_PASSWORD } from "$env/static/private";
const redis = createClient({
url: REDIS_HOST,
password: REDIS_PASSWORD,
});
await redis.connect();
export default redis;
How can I solve this issue?