coolify icon indicating copy to clipboard operation
coolify copied to clipboard

Directus service cannot connect to Redis

Open craigharman opened this issue 1 year ago • 10 comments

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?

craigharman avatar Aug 09 '23 05:08 craigharman

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.

craigharman avatar Aug 09 '23 08:08 craigharman

same problem. Not working with custom redis url, trying to connect localhost redis

PR0F1L3R1 avatar Aug 11 '23 12:08 PR0F1L3R1

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
	};
};

env.js doc

KayhanB avatar Aug 14 '23 11:08 KayhanB

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.

craigharman avatar Aug 15 '23 07:08 craigharman

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.

KayhanB avatar Aug 15 '23 20:08 KayhanB

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?

craigharman avatar Aug 16 '23 04:08 craigharman

sure, i created a repo that using .env file for dev, env.js for production. Hope this helps you.

KayhanB avatar Aug 16 '23 09:08 KayhanB

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.

alexisdechiara avatar Aug 25 '23 12:08 alexisdechiara

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 avatar Sep 13 '23 09:09 valstu

@valstu 's solution worked for me but it has to be REDIS_HOST="somerandomstringhere-redis" the -redis part was needed

0x0m0t0 avatar Sep 25 '23 12:09 0x0m0t0