使用官方postgres镜像运行docker容器,无法访问该容器

时间:2020-03-17 13:25:53

标签: postgresql image docker containers psql

我想在docker容器中运行postgres数据库。 我拉了最新的postgres图片:

docker pull postgres

然后启动容器:

docker run --rm --name pg-docker -e POSTGRES_PASSWORD=docker -d -p 5432:5432 postgres

之后,我尝试访问postgres:

psql -h localhost -U postgres -d postgres

连接失败:

psql: error: could not connect to server: could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432?

could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?

我不明白为什么?

[编辑] 我在Windows 10 Pro上使用Docker Toolbox进行了尝试,但失败了,但是在Ubuntu 18.04上运行良好。

0 个答案:

没有答案