question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fails to connect to redis, when running inside of docker container

See original GitHub issue

Hey, the library works like a charm, thanks a lot. My application is a microservice, which connects to a redis database, which is running inside of docker. However, I can not connect to redis, when my application is running inside of container. I can still connect to redis remotely via cli on other host and it clearly works. I can also run my application outside of docker (directly on my host machine) and it would still connect. But when I build and run the image, it says:

[ioredis] Unhandled error event: Error: connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1085:14)

I also tried to provision my application to docker swarm with compose file on the same network as redis

version: "3"
services:
  myapp:
    image: user/app:latest
    deploy:
      restart_policy:
        condition: on-failure
    ports:
      - "5000:5000"
    networks:
      - webnet

  redis:
    image: redis
    ports:
      - "6379:6379"
    volumes:
      - "./data:/data"
    command: redis-server --appendonly yes
    networks:
      - webnet
      
networks:
  webnet:

But it still wouldn’t connect

Here is the code, I use in my application:

const redis = require('ioredis')
const appdb = new redis()

module.exports = { db }

Thank you in advance.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:28 (2 by maintainers)

github_iconTop GitHub Comments

92reactions
hendrixroacommented, Jan 3, 2019

@MishUshakov Try delete the networks and replace redis section by:

redis:
    image: redis:latest
    command: ["redis-server", "--bind", "redis", "--port", "6379"]

That works for me.

37reactions
luincommented, Dec 12, 2018

Have you tried connecting to Redis via host “redis” (see https://docs.docker.com/compose/networking/)?

const redis = require('ioredis')
const appdb = new redis({host: 'redis'})

module.exports = { db }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Docker can't connect to redis from another service
When you run docker-compose up it runs redis and app in separate containers. Now your app needs to connect/access the redis container (remember ......
Read more >
can't connect to redis at localhost - Docker Desktop for Windows
I have just setup redis using docker in windows and I am trying to write a simple .Net console app to connect to...
Read more >
Docker could not connect to redis at 127.0.0.1:6379 - Bobcares
Redis install inside of Docker container sudo service redis-server start. To restart Redis inside Docker run command:
Read more >
Using Redis in Docker containers - IONOS
To connect to a Redis instance from another Docker container with a command-line interface, link the container and specify the host and port...
Read more >
How to setup and run Redis in a Docker Container - Collabnix
Ensure that Docker is installed · Create a dedicated Docker network · Run Redis container · Install redis-cli · Enter into Redis-cli ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found