我的docker-compose.yml
version: '2.1'
volumes:
kong_data: {}
networks:
kong-net:
services:
kong-migrations:
image: "${KONG_DOCKER_TAG:-kong:latest}"
command: kong migrations bootstrap
depends_on:
db:
condition: service_healthy
environment:
KONG_DATABASE: postgres
KONG_PG_DATABASE: ${KONG_PG_DATABASE:-kong}
KONG_PG_HOST: db
KONG_PG_PASSWORD: ${KONG_PG_PASSWORD:-kong}
KONG_PG_USER: ${KONG_PG_USER:-kong}
links:
- db:db
networks:
- kong-net
restart: on-failure
kong:
image: "${KONG_DOCKER_TAG:-kong:latest}"
user: "${KONG_USER:-root}"
depends_on:
db:
condition: service_healthy
environment:
KONG_ADMIN_ACCESS_LOG: /dev/stdout
KONG_ADMIN_ERROR_LOG: /dev/stderr
KONG_ADMIN_LISTEN: '0.0.0.0:8001'
KONG_CASSANDRA_CONTACT_POINTS: db
KONG_DATABASE: postgres
KONG_PG_DATABASE: ${KONG_PG_DATABASE:-kong}
KONG_PG_HOST: db
KONG_PG_PASSWORD: ${KONG_PG_PASSWORD:-kong}
KONG_PG_USER: ${KONG_PG_USER:-kong}
KONG_PROXY_ACCESS_LOG: /dev/stdout
KONG_PROXY_ERROR_LOG: /dev/stderr
networks:
- kong-net
ports:
- "8000:8000/tcp"
- "8001:8001/tcp"
- "8443:8443/tcp"
- "8444:8444/tcp"
restart: on-failure
db:
image: postgres:9.5
environment:
POSTGRES_DB: ${KONG_PG_DATABASE:-kong}
POSTGRES_PASSWORD: ${KONG_PG_PASSWORD:-kong}
POSTGRES_USER: ${KONG_PG_USER:-kong}
healthcheck:
test: ["CMD", "pg_isready", "-U", "${KONG_PG_USER:-kong}"]
interval: 30s
timeout: 30s
retries: 3
restart: on-failure
stdin_open: true
tty: true
networks:
- kong-net
volumes:
- kong_data:/var/lib/postgresql/data
go-server:
image: gobuild
networks:
- kong-net
restart: on-failure
我的码头工人集装箱
docker ps --format '{{.Names}}'
chapter11_go-server_1
chapter11_kong_1
chapter11_db_1
我正在尝试向在港口8001上运行的Kong admin API发出POST请求。但它失败了。
{
"name": "myapi",
"hosts": "server1",
"": "http://chapter11_go-server_1:3000",
"uris":["/api/v1"],
"strip_uri": true,
"preserve_host": false
}
产量
kong_1 | 172.21.0.1 - - [29/Apr/2019:10:36:58 +0000] "POST /apis HTTP/1.1" 404 23 "-" "PostmanRuntime/7.6.0"
kong_1 | 172.21.0.1 - - [29/Apr/2019:10:47:30 +0000] "POST /apis HTTP/1.1" 404 23 "-" "PostmanRuntime/7.6.0"
如何查看我的POST请求有什么问题?
什么是upstream_url?
根据Kong 1.0.0 changelog:
API实体和相关概念(例如/ apis端点)将被删除(自2011年3月1。0日起不推荐使用)。请改用路由和服务。
由于HK 1.0 /apis
端点不再可用。因此你得到了404 Not not response。
要将API添加到Kong,您必须使用/services
和/routes
。本教程将介绍如何执行此操作:Configuring a Service