7

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)

1 Answer 1

11

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.
Sign up to request clarification or add additional context in comments.

5 Comments

Exposing the port is part of the redis image I am using, see: store.docker.com/images/redis?tab=description
Just try it ) Or you can look at ... or via redis-cli section into your manual.
Just tried it and now I am actually able to connect to 127.0.1 . Very weird. Can you explain that?
Documentation on EXPOSE provides some detail: docs.docker.com/engine/reference/builder/#expose EXPOSE tells it to listen, the user has to actually publish it
Thanks for the very easy to understand explanation @BukharovSergey, that helped me a lot :-).

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.