简体   繁体   中英

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

dockefile EXPOSE 3000 EXPOSE 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

with

sudo docker run -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 .

So instead of specifying localhost as the host in your Redis config, use host.docker.internal . Your Rails app will be able to communicate outside now. -p 6379:6379 is unnecessary

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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