coolify
coolify copied to clipboard
Directus service cannot connect to Redis
I installed Directus in a fresh Coolify instance and the Directus container can't seem to connect to the directus-redis container. I am continually getting logs from DIrectus as follows:
2023-08-09T05:27:40.691728514Z [05:27:40.663] WARN: [system-cache] Error: connect ECONNREFUSED 127.0.0.1:6379
2023-08-09T05:27:40.691732121Z err: {
2023-08-09T05:27:40.691735267Z "type": "Error",
2023-08-09T05:27:40.691738583Z "message": "connect ECONNREFUSED 127.0.0.1:6379",
2023-08-09T05:27:40.691742019Z "stack":
2023-08-09T05:27:40.691745185Z Error: connect ECONNREFUSED 127.0.0.1:6379
2023-08-09T05:27:40.691748361Z at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1495:16)
2023-08-09T05:27:40.691751557Z "errno": -111,
2023-08-09T05:27:40.691754733Z "code": "ECONNREFUSED",
2023-08-09T05:27:40.691757929Z "syscall": "connect",
2023-08-09T05:27:40.691761125Z "address": "127.0.0.1",
2023-08-09T05:27:40.691764542Z "port": 6379
2023-08-09T05:27:40.691767928Z }
It seems strange that the container is looking for REDIS on 127.0.0.1, the environment variable is set as per the default to use the container ID. Can anyone assist?
Looking into this it seems like the environment variables are being ignored and the cache settings aren't in the "configuration" section. I've tested this by setting CACHE_ENABLED
to false
and CACHE_STORE
to memory
but Directus still tries to use localhost and Redis.
I'm new to Coolify so not sure how to fix.
same problem. Not working with custom redis url, trying to connect localhost redis
Directus by default using .env file for env variables so coolify can't override them. Solution is create your own directus repository and deploy it to coolify with env.js file. in js file you can get coolify enviroments.
example of env.js
module.exports = function (env) {
return {
HOST: env.HOST || '0.0.0.0',
PORT: env.PORT || 8055,
// etc
};
};
Directus by default using .env file for env variables so coolify can't override them. Solution is create your own directus repository and deploy it to coolify with env.js file. in js file you can get coolify enviroments.
Are you sure that's the issue? I've searched the Directus container and there is no .env
file? A printenv
also shows the correct Redis details.
I'm not sure how Coolify manages direcuts enviroments but directus creates .env file by default when installed with cli. Actually, I assumed that for this reason. When I started the directus application with cli and deployed it to coolify, I saw that the values in the .env file were based on even if I passed secret from coolify. I reached the solution with env.js.
Yeah, definitely on the right track I just don't think its the .env (as I said, it doesn't actually exist). However its interesting that it seems to find the database credentials. Would you be willing to share your custom Directus repo, or the Dockerfile/docker-compose so I can keep investigating?
sure, i created a repo that using .env file for dev, env.js for production. Hope this helps you.
I've had this problem, after looking at the release list it turns out that there's a breaking change to version 10.4.0, so I recommend using an inferior version like 10.3.0.
Now, that still doesn't fix the issue for future versions.
What worked for me is go to Secrets page, check the value of CACHE_REDIS
it will be something like
redis://somerandomstringhere-redis:6379
Then on the paste .env put following values, REDIS_HOST
being the host from CACHE_REDIS
variable
REDIS_HOST="somerandomstringhere"
REDIS_PORT="6379"
CACHE_STORE="redis"
RATE_LIMITER_STORE="redis"
SYNCHRONIZATION_STORE="redis"
MESSENGER_STORE="redis"
I'm using Directus version 10.6.1
@valstu 's solution worked for me but it has to be
REDIS_HOST="somerandomstringhere-redis"
the -redis
part was needed