Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access dockerized redis from windows host

Tags:

docker

redis

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:

  1. Installed docker
  2. Run 'docker pull redis'
  3. Run 'docker run --name some-redis -d redis redis-server --appendonly yes' to start the redis container

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)

like image 597
kentor Avatar asked Oct 24 '17 18:10

kentor


People also ask

How do I access containers in Windows?

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.

How do I connect to a Redis container?

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.

Can I run Redis on docker windows?

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.


1 Answers

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.

  • you can add -P option to docker run command. In this case docker exposes all defined ports to random ports on you local machine.
  • Or you can add option -p<port_on_host_machine>:<port_inside_docker_container> then you expose certain port.
like image 172
Bukharov Sergey Avatar answered Oct 12 '22 07:10

Bukharov Sergey