I have a Docker container running a C application using hiredis, which should write data to a Redis server exposed at the default address and port running locally on the same Linux device at 127.0.0.1:6379 .
The Redis server is running in a different Docker container. I start this container running, exposing port 6379 as follows : sudo docker run --name redis_container -d -p 6379:6379 40c68ed3a4d2
redsi-cli can connect to this via 127.0.0.1:6379 without issues.
However, no matter what I try, my container which should write to the Redis gets a Redis connection refused error from the C code all the time. This was my last attempt at running the container : sudo docker run --expose=6379 -i 7340dfee8ea5
What exactly am I missing here? Thanks
The
Cclient is running inside a container, that means127.0.0.1points to the container itself, not to your host. You should configure the redis client toredis_container:6379as that is the name you have used when docker run the redis container. More about this hereBesides, both containers need to be inside the same docker network. Use the following command to create a simple network
and add
--network my-netto both docker run commands (redis client and redis server)You can read more about docker network here