2

Not sure if it's the issue with connection string or my docker image. Running docker container ls I see

57cb0c982c76 redis "docker-entrypoint.s…" 0.0.0.0:32773->6379/tcp

The port seems to be mapped to the outside. I tried to run

docker run -d -P redis:alpine

with this and other different variations of parameters, and using StackExchange.Redis C# driver and it times out. Connection string looks like that:

localhost:6379,ssl=True,abortConnect=False

(no password). What am I doing wrong?

UPDATE

Tried with docker run -d -p 6379:6379/tcp redis (also redis:alpine). Still can't connect. docker inspect shows HostConfig:

        "PortBindings": {
            "6379/tcp": [
                {
                    "HostIp": "",
                    "HostPort": "6379"
                }
            ]
        }
2
  • i think the connection string needs to use the container's IP address rather than localhost (run docker inspect <containerId> to get that IP address) Commented Mar 14, 2019 at 22:53
  • 1
    @egnomerator In a wide variety of situations that IP address is not useful; I think on MacOS hosts it's unreachable even from the same host. You never need it directly, and I'd discourage looking it up. Commented Mar 15, 2019 at 1:06

1 Answer 1

4

Since you ran docker run -P (with a capital P), Docker picks a host port for every exposed port in the container. Which port exactly is in the docker ps output: 0.0.0.0:32773->6379/tcp means Docker has picked port 32773, bound to all host interfaces, to forward to TCP port 6379.

This means your Redis client needs to connect to some IP address for the host, on the public-facing port 32773. Changing 6379 to 32773 in your connection string should work.

It's more common to explicitly pick your own port; docker run -p 6379:6379 (lowercase p) would use the "normal" Redis port 6379 on the host to forward to the Redis port in the container. The one downside is that this can fail if anything else is already using that port (a host Redis daemon, some other container).

Sign up to request clarification or add additional context in comments.

1 Comment

Tried it with redis:alpine and redis:latest. None worked. Still can't access it from the host... I'm a bit new to docker, what can I be doing wrong?

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.