0

I have a docker image and i want to connect to the redis database locally.

redis = redis.Redis(
    host='localhost',
    port = 6379,
    charset="utf-8",
    decode_responses=True)

what i typed in to the terminal

sudo docker build -t scraper .
sudo docker run scraper

redis.exceptions.ConnectionError: Error 99 connecting to localhost:6379. Cannot assign requested address.

NB:There was lot of articles here but none of them solved my problem. I am not a geek though so simple explanations will be appreciated.. :)

Sid
  • 301
  • 3
  • 4
  • It is not clear where your Redis database run - is it inside Docker (and it's network) or it's a service on your machine? If it's outside a Docker, you can try running `docker run` command with `--network host` option. Please note, the configuration might be different for each OS. – FN_ Feb 10 '23 at 11:04
  • I think you need to check redis is running or not. Also you need to change `host='localhost'` to `host='redis` – NIKUNJ PATEL Feb 10 '23 at 11:12
  • @FN_ its a service and standalone.i can spin it by redis-cli command and its working properly.and can you explain what is --network host exactly – Sid Feb 10 '23 at 11:49
  • @SiddiqKaithodu I am not sure what exactly you need to explain. You can check official docs. https://docs.docker.com/network/network-tutorial-host/ – FN_ Feb 10 '23 at 12:33

0 Answers0