Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Corbin's avatar

How do I connect redis from dockerized sail server to undockerized nodejs server?

I'm trying to connect my Laravel app using sail to my node/express app (not dockerized) using redis pub/sub:

Sail

redis:
        image: 'redis:alpine'
        ports:
            - '${FORWARD_REDIS_PORT:-6379}:6379'
        volumes:
            - 'sailredis:/data'
        networks:
            - sail
        healthcheck:
          test: ["CMD", "redis-cli", "ping"]
          retries: 3
          timeout: 5s

Node/Express Server

const sub = redis.createClient({port: 6379, host: '0.0.0.0'});

sub.on('message', function () {
    console.log("Message subbed");
});

I know the node server is working because in the redis-cli in a terminal outside the redis docker container I can run redis-cli PUBLISH 'message' 'test' and "Message subbed" get consoled. I have also tried const sub = redis.createClient({port: 6379, host: 'localhost'});

How do I get my node server to subscribe to the dockerized redis? If it's not easy or possible, is there a tutorial to add express to sail?

0 likes
0 replies

Please or to participate in this conversation.