[英]postgresql not reachable in docker-compose
我使用 docker-compose 设置连接到 postgresql 数据库的 web 服务。 当我运行docker-compose up -d
时,会创建 mydb 和 web 服务,但无法从 web 服务访问数据库。 我不明白为什么。
services:
web:
image: etherpad/etherpad:1.8.10
depends_on:
mydb:
condition: service_healthy
ports:
- "6080:9001"
environment:
- DB_TYPE=postgres
- DB_PORT=5432
- DB_HOST=mydb
- DB_NAME=postgres
- DB_USER=etherpad
- DB_PASS=mydbpass
mydb:
image: postgres:13
expose:
- 5432
environment:
- POSTGRES_DB=postgres
- POSTGRES_PASSWORD=mydbpass
- POSTGRES_USER=etherpad
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 10s
timeout: 5s
retries: 5
我修复了它:
systemctl stop nftables
systemctl start docker
systemctl disable nftables
reboot
systemctl start docker
参见:http://github.com/moby/moby/issues/36151#issuecomment-968356070
对于 2 个容器(=服务实例)进行通信,您需要它们之间的网络。
确实 depends_on 是不够的,它只是增加了对启动/构建的约束。
services:
web:
image: etherpad/etherpad:1.8.10
depends_on:
mydb:
condition: service_healthy
ports:
- "6080:9001"
environment:
- DB_TYPE=postgres
- DB_PORT=5432
- DB_HOST=mydb
- DB_NAME=postgres
- DB_USER=etherpad
- DB_PASS=mydbpass
networks:
- backend
mydb:
image: postgres:13
expose:
- 5432
environment:
- POSTGRES_DB=postgres
- POSTGRES_PASSWORD=mydbpass
- POSTGRES_USER=etherpad
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 10s
timeout: 5s
retries: 5
networks:
- backend
networks:
backend:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.