我一直在尝试访问运行在码头容器中的PostgreSQL。我能够从localhost:8080上的adminer中连接到localhost:8080,这是另一个容器,但是我无法从我的主机连接,尽管我正在将端口5432映射到主机。
作为要连接到的容器的IP,我一直在使用从"docker inspect <postgre_container>“(通常是172.21.0.2/3 )获取的IP地址。
这就是我的对接者-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:我很高兴有任何提示,谢谢
发布于 2017-12-01 16:34:38
使用docker inspect显示的IP地址是容器内的内部IP地址。由于您使用的是外部端口5432的端口映射,所以应该通过localhost:5432访问Postgres (例如,127.0.0.1:5432)。
https://stackoverflow.com/questions/47597485
复制相似问题