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.

Connect trough different docker containers | ConnectionRefusedError: [Errno 111] Connection refused

See original GitHub issue

I ran into an issue when connecting to my Redis server when using docker. Am using the latest stable versions of aioredis and Python 3.8.

My docker-compose.yml:

version: "3.8"
services:
  redis-server:
    image: redis:6-alpine
    ports:
      - "6379:6379"
    # volumes: Tried to accept connections from 0.0.0.0
    #   - "./redis.conf:/usr/local/etc/redis/redis.conf"
    # command: [ "redis-server", "/usr/local/etc/redis/redis.conf" ]

  discord-bot:
    image: luc1412/easyfnstats:dev
    restart: unless-stopped
    volumes:
      - "./config:/app/config"
      - "easyfnstats_data:/app/data"
    depends_on:
      - "redis-server"
      - "mongo-database"
    networks:
      - redis

volumes:
  easyfnstats_data:

networks:
  redis:
    driver: bridge

The relevant part of my code:

# Ensure redis is up
for i in range(9, 0, -1):
    logger.info(f'Launch in {i + 1}')
    time.sleep(1)
self._redis = await aioredis.create_redis_pool(REDIS_URI, minsize=1, maxsize=2)

I tried following for REDIS_URI:

  • redis://localhost
  • redis://127.0.0.1
  • redis://redis-server
  • redis://redis

Error:

discord-bot_1     | Process Process-1:
discord-bot_1     | Traceback (most recent call last):
discord-bot_1     |   File "/usr/local/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
discord-bot_1     |     self.run()
discord-bot_1     |   File "/usr/local/lib/python3.9/multiprocessing/process.py", line 108, in run
discord-bot_1     |     self._target(*self._args, **self._kwargs)
discord-bot_1     |   File "/app/launch.py", line 122, in __init__
discord-bot_1     |     self.run()
discord-bot_1     |   File "/usr/local/lib/python3.9/site-packages/discord/client.py", line 708, in run
discord-bot_1     |     return future.result()
discord-bot_1     |   File "/usr/local/lib/python3.9/site-packages/discord/client.py", line 687, in runner
discord-bot_1     |     await self.start(*args, **kwargs)
discord-bot_1     |   File "/app/easy_fortnite_stats.py", line 176, in start
discord-bot_1     |     self.redis = await aioredis.create_redis_pool(
discord-bot_1     |   File "/usr/local/lib/python3.9/site-packages/aioredis/commands/__init__.py", line 188, in create_redis_pool
discord-bot_1     |     pool = await create_pool(address, db=db,
discord-bot_1     |   File "/usr/local/lib/python3.9/site-packages/aioredis/pool.py", line 58, in create_pool
discord-bot_1     |     await pool._fill_free(override_min=False)
discord-bot_1     |   File "/usr/local/lib/python3.9/site-packages/aioredis/pool.py", line 383, in _fill_free
discord-bot_1     |     conn = await self._create_new_connection(self._address)
discord-bot_1     |   File "/usr/local/lib/python3.9/site-packages/aioredis/connection.py", line 111, in create_connection
discord-bot_1     |     reader, writer = await asyncio.wait_for(open_connection(
discord-bot_1     |   File "/usr/local/lib/python3.9/asyncio/tasks.py", line 442, in wait_for
discord-bot_1     |     return await fut
discord-bot_1     |   File "/usr/local/lib/python3.9/site-packages/aioredis/stream.py", line 23, in open_connection
discord-bot_1     |     transport, _ = await get_event_loop().create_connection(
discord-bot_1     |   File "uvloop/loop.pyx", line 1974, in create_connection
discord-bot_1     |   File "uvloop/loop.pyx", line 1951, in uvloop.loop.Loop.create_connection
discord-bot_1     | ConnectionRefusedError: [Errno 111] Connection refused

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
Luc1412commented, Jan 2, 2021

Thanks for the help. I just made a stupid error and just created the bridge between my app and Mongo DB instead of Redis. So it was just a typo.

0reactions
Luc1412commented, Jan 2, 2021

My bad, use redis://redis-server:6379/0 since your container will be “redis-server”, not “redis”, as specified in your compose file.

That results in the same error as above. Also with the removal of ports.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Docker. Failed to establish a new connection: [Errno 111 ...
I want to send post request from one container to another, both are flask apps. When i push send button in form my...
Read more >
HELP!... ConnectionRefusedError: [Errno:111] Connection ...
when in Command Prompt and I try to run 'docker-compose up' Docker-compose starts up, but gets interrupted with the following message:
Read more >
ConnectionRefusedError: [Errno 111] Connection refused
Hello,. I'm using PyODM library for creating orthophotos,. for that I have created flask application. in wich my function looks like this:-
Read more >
New ConnectionError [Errno 111] Connection Refused using ...
I have elasticsearch running in one docker container and elasticsearch-dsl installed in another docker on the same network.
Read more >
Errno 111 Connection refused error when trying to connect to ...
I can connect to the database but when I try to authenticate using the admin user credentials I get "authentication failure error"!
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