ockerized应用连接到本地Redis和Postgresql

ockerized应用连接到本地Redis和Postgresql

本文介绍了将Dockerized应用连接到本地Redis和Postgresql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试了一些教程和指南之后,我试图在docker上设置我的项目.我正在设置具有Redis和Postgresql的Elixir/Phoenix应用程序作为其依赖项.我已经设法使用docker compose对其进行Dockerize,后者将图像用于pg和Redis.

I was trying to setup my project on docker after going through few tutorials and guides. I am setting Elixir/Phoenix app which has Redis and Postgresql as it's dependencies. I have managed to Dockerize it using docker compose which uses images for pg and Redis.

我试图找出一种将Phoenix应用程序连接到本地Postgresql和Redis的方法,而不是将其连接到他们的映像,因为db和Redis需要在服务器上,而不是在Docker容器中.

I was trying to figure out a way to connect my Phoenix app to my local Postgresql and Redis instead of connecting it to their images as the db and Redis needs to be on the server and not in the docker container.

有没有可以帮助我的例子?

Is there any example someone could assist me with ?

谢谢.

推荐答案

默认情况下,容器具有 172.17.0.0/16 网络,而Docker主机的地址为 172.17.0.1 .

By default, containers have 172.17.0.0/16 network and docker host has the address 172.17.0.1.

因此,您只需将PostgreSQL和Redis URL指向该地址,分别为 172.17.0.1:5432 172.17.0.1:6379 .

So you can just point your PostgreSQL and Redis URLs to that address, that is 172.17.0.1:5432 and 172.17.0.1:6379 respectively.

您将需要授予对此网络的连接的访问​​权限 Redis PostgreSQL .

You will need to grant access to connections from this network Redis and PostgreSQL.

这篇关于将Dockerized应用连接到本地Redis和Postgresql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 03:29