2

I want to set up redis configuration in docker.

I have my own redis.conf under D:/redis/redis.conf and have configured it to have bind 127.0.0.1 and have uncommented requirepass foobared

Then used this command to load this configuration in docker:

docker run --volume D:/redis/redis.conf:/usr/local/etc/redis/redis.conf --name myredis redis redis-server /usr/local/etc/redis/redis.conf

Next, I have docker-compose.yml in my application in maven Project under src/resources.

I have the following in my docker-compase.yml

redis:
 image: redis
 ports:
   - "6379:6379"

And i execute the command :

docker-compose up

The Server runs, but when i check with the command:

docker ps -a 

it Shows that redis Image runs at 0.0.0.0:6379.

I want it to run at 127.0.0.1.

How do i get that? isn't my configuration file loading or is it wrong? or my commands are wrong?

Any suggestions are of great help.

PS: I am using Windows.

Thanks

2 Answers 2

1

Try to execute:

docker inspect <container_id>

And use "NetworkSettings"->"Gateway" (it must be 172.17.0.1) value instead of 127.0.0.1.

You can't use 127.0.0.1 as your Redis was run in the isolated environment.

Or you can link your containers.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for ur Reply @Aleksandr Yes it Shows 172.17.0.1. And i changed the bind at redis.conf to bind 172.17.0.1. But again when i do execute the command docker run --volume D:/redis/redis.conf:/usr/local/etc/redis/redis.conf --name myredis redis redis-server /usr/local/etc/redis/redis.conf and execute the command docker-compose up it Shows the same
1

So first of all you should not be worried about redis saying listening on 0.0.0.0:6379. Because redis is running inside the container. And if it doesn't listen on 0.0.0.0 then you won't be able to make any connections.

Next if you want redis to only listen on localhost on localhost then you need to use below

redis:
 image: redis
 ports:
   - "127.0.0.1:6379:6379"

PS: I have not run container or docker for windows with 127.0.0.1 port mapping, so you will have to see if it works. Because host networking in Windows, Mac and Linux are different and may not work this way

9 Comments

thanks for ur Reply. I tried what u said, but surprisingly it says Bind for 127.0.0.1:6379 failed:port is alread allocated. Have no idea what is happening
i just noticed that whenever i Change the bind or uncomment the requirepass, then i get that Connection refused, incase i Keep the ip to 127.0.0.1 or the Gateway and give Password as null in my redis.yml then it works. SO i think my redis.conf isnt loading properly though it Shows configuration loaded
Assuming you are using Docker for Windows, is your D: shared in Docker settings with the Docker VM?
yes i can see my drive being shared in docker settings
The redis bind should always be 0.0.0.0 in config. Also run docker-compose exec redis cat /usr/local/etc/redis/redis.conf to make sure the config you passed is inside the container
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.