pgman
pgman

Reputation: 523

Setting redis configuration with docker in windows

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

Upvotes: 2

Views: 4329

Answers (2)

Tarun Lalwani
Tarun Lalwani

Reputation: 146610

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

Upvotes: 1

Oleksandr Yarushevskyi
Oleksandr Yarushevskyi

Reputation: 3289

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.

Upvotes: 1

Related Questions