2016-08-10 5 views
0

私はpostgres:9.5.3ドッカーイメージを使用しています。私はコンテナを開始し、その後、リモートホストからPSQLデータベースに接続しようとしているが、それぞれの時間は、それはエラーで失敗しています:Postgres Docker - リモートサーバから接続できません

psql: could not connect to server: Connection refused 
Is the server running on host "172.18.0.2" and accepting 
TCP/IP connections on port 5432? 

私のドッキングウィンドウ・コンファイルでは、私はpg_hba.confのを取り付けています。私は指示hereに基づいて、すべてのホストからのリモート接続を受け入れるように、私のpg_hba.confファイルを変更した

services: 
    db: 
     networks: 
     - test 
     image: postgres:9.5.3 
     expose: 
     - 5432 
     volumes: 
     - ./pgdata/:/var/lib/postgresql/data 
     - ./pg_hba.conf/:/var/lib/postgresql/data/pg_hba.conf 

:これは私のドッキングウィンドウ・コンファイルです。

# TYPE DATABASE  USER   ADDRESS     METHOD 

# "local" is for Unix domain socket connections only 
local all    all          trust 
# IPv4 local connections: 
host all    all    0.0.0.0/0    trust 
# IPv6 local connections: 
host all    all    ::0/0     trust 
# Allow replication connections from localhost, by a user with the 
# replication privilege. 
#local replication  postgres        trust 
#host replication  postgres  127.0.0.1/32   trust 
#host replication  postgres  ::1/128     trust 

host all all 0.0.0.0/0 md5 

をそして、私のpostgresql.confのは、あまりにも次の行があります:次のように私にpg_hba.confがあるlisten_addresses = '*'

私は上のコンテナを実行しているホストからデータベースに接続しようと、それ正常に接続します。しかし、コマンドpsql -h 172.18.0.2 -U postgres -d postgres -p 5432を使用してリモートマシンから接続しようとすると、リモート接続が機能していないという接続エラーが表示されます。これらのすべての設定で、私はそれが接続することを期待します。私はここで何が欠けていますか?

+0

"172.18.0.2" 172.0.0.0/8は、ファイアウォール/ルーティング/ブリッジングされていますか? IIRCには172ネットワークに関する特別なものがあります。 – wildplasser

答えて

5

公開されているポートを実際に公開しているようではありません。

の代わり:

expose: 
    - 5432 

使用:

ports: 
- "5432:5432" 

exposeドキュメント:

Expose ports without publishing them to the host machine - they’ll only be accessible to linked services. Only the internal port can be specified.

関連する問題