Skip to content

Instantly share code, notes, and snippets.

@shoyuf
Last active June 8, 2022 08:42
Show Gist options
  • Save shoyuf/dafc2222a894c2a740efd363daa7667c to your computer and use it in GitHub Desktop.
Save shoyuf/dafc2222a894c2a740efd363daa7667c to your computer and use it in GitHub Desktop.
kong and konga for docker compose yaml
# 数据库初始化之前会有多次错误提示,不要心急
version: "3.7"
services:
# kong
kong:
# 镜像版本,目前使用2.8.1
image: kong:2.8.1
user: kong
depends_on:
- kong-postergres-init
environment:
# 数据持久化方式,使用postgres数据库
- "KONG_DATABASE=postgres"
# 数据库容器名称,Kong连接数据时使用些名称
- "KONG_PG_HOST=kong-database"
- "KONG_PG_PASSWORD=kong"
# 数据库名称
# - "KONG_CASSANDRA_CONTACT_POINTS=kong-database"
# 日志记录目录
- "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:
- 80:8000
- 443:8443
- 127.0.0.1:8001:8001
- 127.0.0.1:8444:8444
networks:
- kong-net
healthcheck:
test: ["CMD", "kong", "health"]
interval: 10s
timeout: 10s
retries: 10
restart: on-failure
# kong 管理界面
konga:
image: pantsel/konga
depends_on:
- kong-database
environment:
- "TOKEN_SECRET=secret_0"
- "NODE_ENV=production"
- "DB_ADAPTER=postgres"
- "DB_URI=postgresql://kong:kong@kong-database/konga_database"
ports:
- 8002:1337
networks:
- kong-net
healthcheck:
test: wget --quiet --tries=1 --spider http://127.0.0.1:1337 || exit 1
interval: 10s
timeout: 10s
retries: 10
restart: always
# kong 数据库初始化
kong-postergres-init:
image: kong:latest
command: kong migrations bootstrap
depends_on:
- kong-database
environment:
- KONG_DATABASE=postgres
- KONG_PG_HOST=kong-database
- KONG_PG_PASSWORD=kong
networks:
- kong-net
restart: on-failure
# konga 数据库初始化
konga-postgres-init:
image: pantsel/konga
command: -c prepare -a postgres -u postgresql://kong:kong@kong-database/konga_database
depends_on:
- kong-database
networks:
- kong-net
restart: on-failure
# 数据库服务
kong-database:
image: postgres:9.5
ports:
- "5432:5432"
environment:
# 访问数据库的用户
- POSTGRES_USER=kong
- POSTGRES_DB=kong
- POSTGRES_PASSWORD=kong
healthcheck:
test: ["CMD", "pg_isready", "-U", "kong", "-d", "kong"]
interval: 30s
timeout: 30s
retries: 3
restart: on-failure
stdin_open: true
tty: true
networks:
- kong-net
volumes:
# 数据库持久化目录
- ./postgresql:/var/lib/postgresql/data
# # 同步时间
# - /etc/localtime:/etc/localtime:ro
networks:
kong-net:
external:
name: kong-net
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment