我使用 docker 为一个项目编写 Vapor、PostgreSQL 和 Nginx,我的 docker-compose.yml 是这样的:
version: "3.6"
services:
vapor:
build:
context: ./vapor
image: ${CURRENT_VAPOR_IMG}
ports:
- 8080:8080
volumes:
- ${HOST_ROOT}:${CONTAINER_ROOT}
working_dir: ${CONTAINER_ROOT}
tty: true
entrypoint: bash
networks:
- x-net
nginx:
build:
context: ./nginx
image: ${CURRENT_NGINX_IMG}
ports:
- ${HOST_HTTP_PORT}:80
volumes:
- ${HOST_ROOT}:${CONTAINER_ROOT}
networks:
- x-net
psql:
image: ${CURRENT_DB_IMG}
ports:
- 5432:5432
environment:
- POSTGRES_DB=xxx
- POSTGRES_USER=xxx
- POSTGRES_PASSWORD=pass
volumes:
- ~/x/x-db:/var/lib/postgresql/data
networks:
- x-net
networks:
x-net:
driver: bridge
我运行docker-compose up启动所有容器后,进入vapor的容器构建&&运行项目,控制台会提示错误:
NIO.ChannelError.connectFailed(NIO.NIOConnectionError(host: "localhost", port: 5432, dnsAError: nil, dnsAAAAError: nil, connectionErrors: [NIO.SingleConnectionFailure(target: [IPv6]localhost/::1:5432, error: connection reset (error set): Connection refused (errno: 61)), NIO.SingleConnectionFailure(target: [IPv4]localhost/127.0.0.1:5432, error: connection reset (error set): Connection refused (errno: 61))]))
然后我在本地机器上运行 vapor 项目并保持 psql 容器运行,它可以正常工作,例如完成第一次模型迁移。
我的 docker 配置或其他配置有什么错误吗?