docker安装kong网关
其中docker-compose.yml配置
version: '3.1'
services:
cc-postgres-serve:
#postgres 数据库 空网关使用
build:
context: ./../dockerfile/postgres-server
dockerfile: Dockerfile
environment:
POSTGRES_DB: kong
POSTGRES_PASSWORD: kong
POSTGRES_USER: kong
healthcheck:
test: [ "CMD", "pg_isready", "-U", "kong" ]
interval: 30s
timeout: 30s
retries: 3
restart: on-failure
stdin_open: true
tty: true
ports:
# - "5432:5432/tcp"
- "5432:5432"
container_name: cc-postgres-serve
networks:
- locnet
# 空网关服务
cc-kong-serve:
build:
context: ./../dockerfile/kong-server
dockerfile: Dockerfile
container_name: cc-kong-serve
restart: on-failure
environment:
- KONG_DATABASE=postgres
- KONG_PG_HOST=10.1.160.254
- KONG_PG_USER=kong
- KONG_PG_PASSWORD=kong
- KONG_PG_DATABASE=kong
- KONG_PROXY_ACCESS_LOG=/dev/stdout
- KONG_ADMIN_ACCESS_LOG=/dev/stdout
- KONG_PROXY_ERROR_LOG=/dev/stderr
- KONG_ADMIN_ERROR_LOG=/dev/stderr
- KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl
ports:
- "8000:8000"
- "8443:8443"
- "8001:8001"
- "8444:8444"
links:
- cc-postgres-serve
depends_on:
- cc-postgres-serve
networks:
- locnet
cc-konga-serve:
build:
context: ./../dockerfile/konga-server
dockerfile: Dockerfile
environment:
NODE_ENV: production
ports:
- "1337:1337/tcp"
depends_on:
- cc-kong-serve
container_name: cc-konga-serve
对应的dockerfile
kong
FROM kong
konga
FROM pantsel/konga
postgres
FROM postgres:9.6
步骤
1、直接启动docker-compose up -d
会发现kong会报错一直重启,那是因为没有初始化postgre数据库
2、外部先手动执行一下初始化
docker run --rm \
--network=locnet \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=10.1.160.254" \
-e "KONG_CASSANDRA_CONTACT_POINTS=kong" \
-e "KONG_PG_PASSWORD=kong" \
server_cc-kong-serve kong migrations bootstrap
3、然后再重新启动kong这个服务就可以了,也可以docker-compose up -d
4、访问konga管理kong
配置kong
流程就是 客户端访问route,然后route找到根据path找到对应的服务,服务再找到对应实际接口对应的地址