Reputation: 11
Any ideas why I get a connection error when trying to run a redis command from one container to another? I'm trying to run an old python 2.7 lambda locally in order to test before upgrading to 3.8.10 I'm running a script that builds and links redisdb container with my_app container:
docker build . -t my_app:latest
docker pull redis:3.2.4-alpine && \
docker run --name=redisdb -d redis:3.2.4-alpine redis-server
docker run \
--rm -t -i -d \
--link redisdb:redis \
-h redis -p 6379 \
-e CONFIG_FILE=local_config.yaml \
my_app
I am running a python script on my_app with the following commands:
r = redis.Redis()
r.mset({"Bahamas": "Nassau"})
print(r.get("Bahamas"))
I've also tried the top suggestion here: Error 99 connecting to localhost:6379. Cannot assign requested address and passed r = redis.Redis(host='localhost', port=6379, decode_responses=True)
with the same results.
Every time I try to run that python script in the my_app container, I get:
redis.exceptions.ConnectionError: Error 99 connecting to localhost:6379. Cannot assign requested address.
When I run the containers and then check docker ps
I get this:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
76aea9308821 mar-atlas-readings-processor "python2" About a minute ago Up About a minute 0.0.0.0:64098->6379/tcp mar-atlas-readings-processor
f313113341de redis:3.2.4-alpine "docker-entrypoint.s…" About a minute ago Up About a minute 6379/tcp redisdb
This shows the correct port connections.
Upvotes: 0
Views: 2070
Reputation: 320
Your python app is trying to talk to Redis on localhost but the Redis container is on a different localhost.
You should be able to use the link configured in the docker run ...
command, i.e redisdb
, for the host
option.
Upvotes: 1