简体   繁体   English

无法托管机器的 redis 到 docker 导轨应用程序

[英]not able to host machine's redis to docker rails app

I'm trying to connect my rails app which is in the docker container and trying to connect that to host machine's Redis server which is running on port 6379. I'm getting我正在尝试连接 docker 容器中的 Rails 应用程序,并尝试将其连接到在端口 6379 上运行的主机 Redis 服务器。我得到了

dockefile EXPOSE 3000 EXPOSE 6379停靠文件 暴露 3000 暴露 6379

sudo docker run -it -e RAILS_ENV=development -p 3000:3000 -p 6379:6380 <containerid>

gives error给出错误

Redis::ConnectionError: Connection lost (ECONNRESET)
when redis is running on 6380.

and

when I try to run Redis on 6379 I get the following error当我尝试在 6379 上运行 Redis 时,出现以下错误

with

sudo docker run -it -e RAILS_ENV=development -p 3000:3000 -p 6379:6379须藤 docker 运行 -it -e RAILS_ENV=development -p 3000:3000 -p 6379:6379

docker: Error response from daemon: driver failed programming external connectivity on endpoint vigorous_turing (2b5c8e2b4f5df5f1bfcccfdfc87fd5ea78c5c2643de4e00774e7dec67acbd8c4): Error starting userland proxy: listen tcp 0.0.0.0:6379: bind: address already in use.

If Redis is running on the host and you want to communicate outside the container, docker recommends using host.docker.internal .如果 Redis 在宿主机上运行,你想在容器外进行通信,docker 建议使用host.docker.internal

So instead of specifying localhost as the host in your Redis config, use host.docker.internal .因此,不要在 Redis 配置中指定localhost作为主机,而是使用host.docker.internal Your Rails app will be able to communicate outside now.现在,您的 Rails 应用程序将能够与外部通信。 -p 6379:6379 is unnecessary -p 6379:6379是不必要的

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM