For node backend development on windows I am trying to setup redis in a docker container as the redis windows version seems to be buggy for me. I am very new to docker and I am not aware of all the principles coming along with it.
What I have done so far:
The problem:
I tried connecting to 127.0.0.1:6379 (which used to work when I had redis installed natively on my system), but it is timeouting. I thought that the redis container has it's own ip address and I figured it's ip addres sis 172.17.0.2. Connecting to this ip didn't work either though.
PS C:\WINDOWS\system32> docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' some-redis
172.17.0.2
PS C:\WINDOWS\system32> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d3b796e9df5c redis "docker-entrypoint..." About an hour ago Up 8 minutes 6379/tcp some-redis
What am I missing in order to connect from my local machine to redis inside of my container? (My node application is not dockerized)
Run a Windows container using Windows Admin Center First, open the container host you want to manage, and in the Tools pane, select the Containers extension. Then, select the Images tab inside the Container extension under Container Host. In the Pull Container Image settings, provide the image URL and the tag.
To connect to a Redis instance from another Docker container, add --link [Redis container name or ID]:redis to that container's docker run command. To connect to a Redis instance from another Docker container with a command-line interface, link the container and specify the host and port with -h redis -p 6379.
You can either use redis via the WSL or use this image built natively for docker Windows. There is the latest version officially ported by Microsoft as well as the latest versions ported by the community.
You miss to expose port. Run redis container with command
docker run --name some-redis -p6379:6379 -d redis redis-server --appendonly yes
If Dockerfile
contains EXPOSE <some_port>
it means another containers into same docker network can connect to this port. Nothing more.
If you want to connect to container from host machine you need say docker about it.
-P
option to docker run
command. In this case docker
exposes all defined ports to random ports on you local machine. -p<port_on_host_machine>:<port_inside_docker_container>
then you expose certain port.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With