我在运行服务时遇到网络问题docker-compose
。本质上,我只是想通过 Kong 向我设置的简单 Flask API 发出获取请求。docker-compose.yml 低于版本:“3.0”
services:
postgres:
image: postgres:9.4
container_name: kong-database
ports:
- "5432:5432"
environment:
- POSTGRES_USER=kong
- POSTGRES_DB=kong
web:
image: kong:latest
container_name: kong
environment:
- DATABASE=postgres
- KONG_PG_HOST=postgres
restart: always
ports:
- "8000:8000"
- "443:8443"
- "8001:8001"
- "7946:7946"
- "7946:7946/udp"
links:
- postgres
ui:
image: pgbi/kong-dashboard
container_name: kong-dashboard
ports:
- "8080:8080"
employeedb:
build: test-api/
restart: always
ports:
- "5002:5002"
我使用命令将 API 添加到 kong curl -i -X POST --url http://localhost:8001/apis/ --data name=employeedb --data upstream_url=http://localhost:5002 --data hosts=employeedb --data uris=/employees
。我已经尝试了许多输入组合,包括不同的名称、传入 Docker 网络 IP 和 test-api 的名称作为 upstreamurl 的主机名。将 API 添加到 Kong 后,我得到
HTTP/1.1 502 Bad Gateway
Date: Tue, 11 Jul 2017 14:17:17 GMT
Content-Type: text/plain; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Server: kong/0.10.3
此外,我已经进入运行的 docker 容器docker exec it <container-id> /bin/bash
并尝试向预期的烧瓶端点发出 curl 请求。在运行 API 的容器上,我能够成功调用两者localhost:5002/employees
以及employeedb:5002/employees
. 但是,当我从运行 Kong 的容器中制作它时,我看到了
curl -iv -X GET --url 'http://employeedb:5002/employees'
* About to connect() to employeedb port 5002 (#0)
* Trying X.X.X.X...
* Connection refused
* Failed connect to employeedb:5002; Connection refused
* Closing connection 0
我是否缺少某种将容器相互公开的配置?