如何将本地计算机上运行的Postgres数据库连接到docker容器

时间:2017-06-29 20:42:59

标签: postgresql docker docker-networking

我在容器上运行Flask应用程序,在本地计算机上运行Postgres数据库,现在,我想将Postgres数据库(在5432上监听)连接到docker容器。

任何人都可以建议最好的方法吗? (我是Docker容器的新手)

提前致谢。

2 个答案:

答案 0 :(得分:1)

您可能希望将Postgres数据库停靠在自己的容器中,并使用持久卷在本地存储数据。

如何对Postgres数据库进行Docker化的教程:https://docs.docker.com/engine/examples/postgresql_service/

Docker卷上的文档:https://docs.docker.com/engine/tutorials/dockervolumes/

Docker Hub上的Postgres图像:https://hub.docker.com/_/postgres/

答案 1 :(得分:0)

您可以使用本地计算机的IP地址连接Docker容器中的postgres。 localhost将无法在某些计算机中解析。

你可能对这篇文章感兴趣。 From inside of a Docker container, how do I connect to the localhost of the machine?

相关问题