我可以連接到我的本地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