简体   繁体   English

如何连接到 dockerized Redis 服务器?

[英]How to connect to dockerized Redis Server?

I am unable to connect (timeout) to a dockerized redis server 1 which was started with the command of:我无法连接(超时)到使用以下命令启动的 dockerized redis 服务器1

docker run -it --rm -p 6379:6379 redis:alpine

I've tried to start the server with configs :我试图用配置启动服务器:

set bind to 0.0.0.0
protected-mode no

I am however able to connect to my redis server with another docker container with the following command:但是,我可以使用以下命令使用另一个 docker 容器连接到我的 redis 服务器:

docker run -it --rm redis:alpine redis-cli -h host.docker.internal -p 6379

and also tried configuring the same parameters through cli as well.并且还尝试通过 cli 配置相同的参数

When I try to connect the connection times out, I tried with both internal ip当我尝试连接时连接超时,我尝试了两个内部 ip

172.17.0.x

and with the internal domain name:并使用内部域名:

host.docker.internal

to no avail.无济于事。 Further note that I was able to connect to redis server when installed with进一步注意,安装时我能够连接到 redis 服务器

brew install redis

on the host.在主机上。

What am I missing, how can I resolve the issue so that I can connect to redis-server that is within a docker container from the container's host?我错过了什么,我该如何解决这个问题,以便我可以从容器主机连接到 docker 容器内的 redis-server?


Environment details环境详情
OS: MacOS Monterey Version: 12.6 (21G115)

Docker version 20.10.17, build 100c701

1 More specifically I've tried with both rdcli -h host.docker.internal in the mac terminal and also on application side with StackExchange.Redis . 1更具体地说,我已经尝试在 mac 终端中使用rdcli -h host.docker.internal ,也在应用程序端使用StackExchange.Redis

More specifically I've tried with both rdcli -h host.docker.internal in the mac terminal更具体地说,我在 mac 终端中尝试了 rdcli -h host.docker.internal

The host.docker.internal is a DNS name to access the docker host from inside a container. host.docker.internal是一个 DNS 名称,用于从容器内部访问 docker 主机。 It's a bad practice to use this inside one container to talk to another container.在一个容器内使用它来与另一个容器通信是一种不好的做法。 Instead you'd create a.network, create both containers in that.network, and use the container name to connect.相反,你会创建一个.network,在那个.network 中创建两个容器,然后使用容器名称进行连接。 When that's done, the port doesn't even need to be published.完成后,端口甚至不需要发布。

From the host, that's when you connect to the published port.从主机上,就是您连接到已发布端口的时间。 Since the container is deployed with -p 6379:6379 , you should be able to access that port from the hostname of your host, or localhost on that host:由于容器是使用-p 6379:6379部署的,因此您应该能够从主机的主机名或该主机上的本地主机访问该端口:

rdcli -h localhost

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 dockerized spring boot 连接 dockerized couchbase 服务器 - How to connect dockerized couchbase server from dockerized spring boot 将dockerized redis迁移到另一台服务器 - Migrating dockerized redis to another server Dockerized GAE 应用程序无法连接到 Redis 实例 - Dockerized GAE app fails to connect to Redis instance 无法连接到 dockerized postgresql 服务器 - cant connect to dockerized postgresql server 如何从 dockerized python 应用程序连接到本地 sql server 数据库 - How to connect to local sql server database from dockerized python app Dockerized Zuul Gateway 无法连接到 Dockerized Eureka Server - Dockerized Zuul Gateway failing to connect to dockerized Eureka Server 为什么我的 dockerized nodejs 服务器无法连接到我的 dockerized mongodb? - Why is my dockerized nodejs server not able to connect to my dockerized mongodb? 无法从 Spring 引导连接到外部/内部机器中的 Dockerized Redis - Unable to connect from Spring Boot to Dockerized Redis in outside/inside machine 无法从docker外部连接到dockerized redis实例 - Unable to connect to dockerized redis instance from outside docker 芹菜工人无法使用Django连接到dockerized redis实例 - celery workers unable to connect to dockerized redis instance using Django
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM