我可以连接到我的本地Postgres数据库在我的web应用程序中,但是不是如果我正在Docker容器中运行Web应用程序。Docker容器与Python Web应用程序 - 连接到主机上的Postgres机器(OSX)
泊坞窗容器运行的内部运行
- 的Web应用程序,我不知道这是否是与Postgres的连接设置或泊坞窗网络设置。
按照我的设置和命令:
主机:
- OSX 10.11.6
- 的PostgreSQL 9.6
泊坞容器
- 泊坞1.13.1
- 多克尔机0.9.0
- 多克尔容器OS:蟒:3.6.0高山
- 的Python 3.6 + psycopg2 == 2.7
postgresql.conf中:
listen_addresses = '*'
的pg_hba.conf
host all all 127.0.0.1/32 trust host all all 0.0.0.0/0 trust host all all 172.17.0.0/24 trust host all all 192.168.99.0/24 trust
随着HOST模式泊坞网络
docker run -i --net=host -h 127.0.0.1 -e POSTGRES_URI=postgresql://127.0.0.1:5432/db my/image
错误:
could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432?随着BRIDGE模式泊坞网络
docker run -i --add-host=dockerhost:`docker-machine ip ${DOCKER_MACHINE}` -e POSTGRES_URI=postgresql://dockerhost:5432/db -p 8000:8000 -p 5432:5432 my/image
错误:
server closed the connection unexpectedly
This probably means the server terminated abnormally before or while processing the request.任何想法?
有什么特别的原因,在一个容器没有运行的Postgres以及做备注? – R0MANARMY