Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

3.7K
Vistas
Error 99 connecting to localhost:6379. Cannot assign requested address

Setup: I have a virtual machine and in the virtual machine running three containers (an nginx proxy, a very minimalistic flask app and redis). Flask should be serving on port 5000 while redis on 6379.

Each of these containers are up and running just fine as stand a lone services, but also available via docker compose as a service.

In the flask app, my aim is to connect to redis and query for some keys.

The nginx container exposes port 80, flask port 5000 and redis port 6379.

In the flask app I have a function that tries to create a redis client

db = redis.Redis(host='localhost', port=6379, decode_responses=True)

Running the flask app I am getting an error that the port cannot be used

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

I am lost of clarity what could be causing this problem and any ideas would be appreciated.

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

In the flask app I have a function that tries to create a redis client

db = redis.Redis(host='localhost', port=6379, decode_responses=True)

When your flask process runs in a container, localhost refers to the network interface of the container itself. It does not resolve to the network interface of your docker host.

So you need to replace localhost with the IP address of the container running redis.

In the context of a docker-compose.yml file, this is easy as docker-compose will make service names resolve to the correct container IP address:

version: "3"
services:
  my_flask_service:
    image: ...
  my_redis_service:
    image: ...

then in your flask app, use:

db = redis.Redis(host='my_redis_service', port=6379, decode_responses=True)
over 4 years ago · Santiago Trujillo Denunciar

0

I had this same problem, except the service I wanted my container to access was remote and mapped via ssh tunnel to my Docker host. In other words, there was no docker-compose service for my code to find. I solved the problem by explicitly telling redis to look for my local host as a string:

pyredis.Redis(host='docker.for.mac.localhost', port=6379)
over 4 years ago · Santiago Trujillo Denunciar

0

Anyone using only docker to run a container, you can add --network=host in the command like docker run --network=host to make docker use the network of the host while running the container.

You can also use a host network for a swarm service, by passing --network host to the docker service create command.
Make sure you don't publish any port while doing this. like -p 80:8000

I am not sure if Docker compose supports this.

N.b. this is only supported in linux.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda