我一直在嘗試碼頭容器postgres。到目前爲止,我還沒有能夠連接到容器內的數據庫。碼頭集裝箱Postgres連接錯誤
我的步驟重新創建下面的問題。
dockerfile開始
FROM postgres
ENV POSTGRES_DB db
ENV POSTGRES_USER postgres
ENV POSTGRES_PASSWORD postgres
COPY db_schema.sql /docker-entrypoint-initdb.d/
我建的,像這樣
$ docker build -t db_con .
泊塢窗文件並開創了容器查看運行的容器如下
的$ docker run -it -p 5432:5432 --name test_db db_con /bin/bash
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
82347f1114c4 db "docker-entrypoint..." 3 hours ago Up 2 sec 0.0.0.0:5432->5432/tcp test_db
我檢查的容器的地址信息..
$ docker inspect test_db
--extract start--
"Networks": {
"bridge": {
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
}
}
--extract end--
現在,我已經在容器內嘗試過,但我一直沒成功。 我已經嘗試了下面的錯誤與下面的錯誤。
[email protected]:/# psql -U postgres -h 0.0.0.0 -p 5432 -d db
[email protected]:/# psql -U postgres -h 172.17.0.1 -p 5432 -d db
[email protected]:/# psql -U postgres -h 172.17.0.2 -p 5432 -d db
**response for all the above**
psql: could not connect to server: Connection refused
Is the server running on host "0.0.0.0" and accepting
TCP/IP connections on port 5432?
如果有人能指出我正確的方向,我會很高興。我在這裏碰壁了,任何幫助都非常感謝。
嘗試所有這些東西,例如創建模式,從外部連接到數據庫實例(即在容器生命週期之外)。這是更有用的方法。 –