Fails to connect to redis, when running inside of docker container
See original GitHub issueHey, 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:
- Created 5 years ago
- Reactions:1
- Comments:28 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@MishUshakov Try delete the networks and replace redis section by:
That works for me.
Have you tried connecting to Redis via host “redis” (see https://docs.docker.com/compose/networking/)?