我具有以下架构:
A network with 3 containers:
container_db, running PostgreSQL
container_pg_admin, running a simple pgAdmin environment
container_php_dev, running the whole environment, needed for the application to function properly (nginx, php, angular for the frontend, etc.)
当我尝试从container_php_dev到pg_connect()到container_db时,连接被拒绝。这是我收到的实际错误消息:pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: No route to host↵ Is the server running on host "container_db" (172.18.0.4) and accepting↵ TCP/IP connections on port 5432?
。
但是,当我尝试从container_db
连接到container_pg_admin
时,实现此目标没有问题(主机为container_db
,端口为5432)。即使我将container_db
的端口5432映射到主机上的5555,也可以从DBeaver或其他DB Manager(TeamSQL)连接到127.0.0.1:5555。
所有容器以及docker本身都重新启动了几次。由于这是我的开发机器,因此主机PC也已重新启动。
可能是什么问题,如何诊断和解决?你们有没有经历过这种奇怪的码头工人行为?
答案 0 :(得分:0)
尝试使用标志container_db
在托管网络中运行--network host