首先确保系统安装了docker和docker-compose
然后新建docker-compose.yaml文件,编辑如下内容
version: '2'
networks:
kong-net:
driver: bridge
services:
kong-database:
image: postgres:9.6
container_name: kong-database
restart: always
networks:
- kong-net
environment:
POSTGRES_USER: kong
POSTGRES_DB: kong
POSTGRES_PASSWORD: kong
ports:
- "5432:5432"
#kong数据库的初始化应用,执行一遍即可注释
kong-migration:
container_name: kong-migration
image: kong:latest
command: "kong migrations bootstrap"
networks:
- kong-net
restart: on-failure
environment:
KONG_PG_HOST: kong-database
KONG_DATABASE: postgres
KONG_PG_USER: kong
KONG_PG_PASSWORD: kong
KONG_CASSANDRA_CONTACT_POINTS: kong-database
links:
- kong-database
depends_on:
- kong-database
# 启动kong
kong:
container_name: kong
image: kong:latest
restart: always
networks:
- kong-net
environment:
TZ: Asia/Shanghai
KONG_DATABASE: postgres
KONG_PG_HOST: kong-database
KONG_PG_USER: kong
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
depends_on:
- kong-migration
- kong-database
ports:
- "8001:8001"
- "8000:8000"
- "8443:8443"
- "8444:8444"
#konga数据库的初始化应用,执行一遍即可注释
konga-prepare:
container_name: konga-prepare
image: pantsel/konga:latest
command: "-c prepare -a postgres -u postgresql://kong:kong@kong-database:5432/konga"
networks:
- kong-net
restart: on-failure
links:
- kong-database
depends_on:
- kong
- kong-database
#启动kong,使用postgres数据库存储数据
konga:
container_name: konga
image: pantsel/konga:latest
restart: always
networks:
- kong-net
environment:
DB_ADAPTER: postgres
DB_HOST: kong-database
DB_USER: kong
DB_DATABASE: konga
DB_PASSWORD: kong
depends_on:
- kong
- kong-database
ports:
- "1337:1337"
docker-compose启动容器
docker-compose -f docker-compose.yml up -d