I am using a redis-server:latest image. I used "docker run -it --name="redis2" redis:1 bash" command and got inside the container. I saw that by default redis is listening to Port: 6379.
Running in stand alone mode Port: 6379 PID: 39 [39] 01 Mar 09:03:45.669 # Server started, Redis version 2.8.4 [39] 01 Mar 09:03:45.669 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect. [39] 01 Mar 09:03:45.669 * The server is now ready to accept connections on port 6379
And then further there is no response. I tried "redis-cli ping". There was no response. Then I hit "ctrl+c" and type, "redis-cli ping" and get following response:
Could not connect to Redis at 127.0.0.1:6379: Connection refused I tried to change the port to 6001 by executing following:
redis-server --port 6003 And I see following response:
Running in stand alone mode Port: 6003 PID: 47 And again I tried "redis-cli ping" and it threw me the same error:
Could not connect to Redis at 127.0.0.1:6379: Connection refused How do I fix this? Also I have updated the port(the new port 6003) in "/etc/redis/redis.conf" location.
Thank you
4 Answers
Redis is listening on that port on the internal docker network, to access it from your local machine you need to map the container port to your local port using -p 6379:6379. That way if you have multiple redis containers you can map them each to different ports on your machine.
4If you are getting this error:
Could not connect to Redis at 127.0.0.1:6379: Connection refused
You may need to daemonize the redis-server so that docker can connect to it:
/usr/local/bin/redis-server --daemonize yes
Then try running redis-cli ping again.
Well, it's been a while but for anybody else faced the same issue; when you put the "sh" command in "docker run" it replaces the default command which is starting Redis server. So you can either spin up the container in a separate terminal like "docker run redis" and in another terminal run "docker exec -it #container_id sh" which is a more common way to start up your container in a primary process and then attach a running shell to it or map the container port to your local port as Chris suggested.
Ok, I had the same problem tonight.
I was using a Redis container created from my docker-compose.yml:
redis: container_name: 'myproject-redis' image: redis:latest ports: - "127.0.0.1:${HOST_MACHINE_REDIS_PORT}:6379" My solution was to use the container "ID" -> here 'redis' instead of using the normal connection IP 127.0.0.1.
Why ? I assume that my Docker was creating a bridge directly to the created container (like it's often the case for MySQL i.e.).