我已经成功构建了一个 postgres基于 Docker image that enables PostGIS :
我运行它:
docker run -d -t -p 5432:5432 -v ./data:/data --name postgis-osm-pgrouting -e POSTGRES_PASSWORD=postgres pamtrak06/postgis-pgrouting-osm bash
但是,当我尝试通过 psql 连接到数据库时:
psql -h localhost -p 5432 postgres
我得到一个错误:
psql: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
我是端口转发的初学者,但对我来说这似乎是一个与端口相关的问题。
有什么想法吗?
最佳答案
要从您的容器中访问应用程序,您需要先“附加”到该容器。
您可以通过运行命令来执行此操作:
docker exec -it container_name sh
此命令的作用是在容器 container_name
中运行命令 sh
它将提示一个 shell 终端,您现在可以在其中运行 psql 命令,如下所示:
psql -U postgres
在这里你用用户 postgres(psql 的默认授权用户)运行 psql
关于postgresql - psql 无法访问在 Docker 容器中运行的 Postgres,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50910022/