我一直在尝试码头容器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?
如果有人能指出我正确的方向,我会很高兴。我在这里碰壁了,任何帮助都非常感谢。
尝试所有这些东西,例如创建模式,从外部连接到数据库实例(即在容器生命周期之外)。这是更有用的方法。 –