Docker的最新版本不再使用虛擬機,而是使用虛擬機管理程序連接到容器。這意味着我再也不能登錄到與psql
Postgres的:如何連接到Mac上的Docker(1.12.0)容器中的Postgres服務器?
➜ postgres git:(master) ✗ docker run -d -p 5433:5432 db postgres
<sha>
➜ postgres git:(master) ✗ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
111f3bed4c52 db "/docker-entrypoint.s" 17 minutes ago Up 17 minutes 0.0.0.0:5433->5432/tcp zen_hugle
➜ postgres git:(master) ✗ psql -p 5433 -U postgres
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5433"?
我也曾嘗試localhost指定爲主機,而導致一個奇怪的輸出:
➜ postgres git:(master) ✗ psql -h localhost -p 5433 -U postgres
psql: %
有誰知道該怎麼做在這種情況下?謝謝。
僅供參考,它確實使用VM,而不是VirtualBox,它在Mac上使用xhyve虛擬機,但使用Unix套接字進行網絡連接。如果您需要「本地」模型(例如,更接近模仿生產系統),則最好使用傳統VM環境。 – ldg
我假設在你的run聲明中它應該是'docker run -d -p 5433:5432 --name = db postgres' – ldg