Docker中的PostgreSQL – 从主机访问
我一直在尝试访问Docker容器中运行的PostgreSQL。 我可以从localhost:8080
上的admhost连接到PostgreSQL,这是另一个容器,但是我不能从我的主机连接,尽pipe我将端口5432
映射到主机。
作为一个容器的IP连接,我一直在使用从“ docker inspect <postgre_container>
”获取的IP地址 – 通常是172.21.0.2/3
。
这就是我的docker-compose.yml的样子:
version: '3.1' services: db: image: postgres:9.6.0 restart: always environment: POSTGRES_PASSWORD: root POSTGRES_USER: root ports: - "5432:5432" volumes: - pgdata:/var/lib/postgresql/data adminer: image: adminer restart: always ports: - 8080:8080 volumes: pgdata:
我会很高兴任何提示,谢谢
使用docker inspect
显示的IP地址是容器内的内部 IP地址。 由于您正在使用外部端口5432的端口映射,您应该通过localhost:5432(例如127.0.0.1:5432)访问Postgres。