linux 安装kong gateway
-
Create a Docker network
You will need to create a custom network to allow the containers to discover and communicate with each other. In this example
kong-net
is the network name, you can use any name.$ docker network create kong-net
-
Start your database
If you wish to use a Cassandra container:
$ docker run -d --name kong-database \ --network=kong-net \ -p 9042:9042 \ cassandra:3
If you wish to use a PostgreSQL container:
$ docker run -d --name kong-database \ --network=kong-net \ -p 5432:5432 \ -e "POSTGRES_USER=kong" \ -e "POSTGRES_DB=kong" \ postgres:9.6
-
Prepare your database
Run the migrations with an ephemeral Kong container:
$ docker run --rm \ --network=kong-net \ -e "KONG_DATABASE=postgres" \ -e "KONG_PG_HOST=kong-database" \ -e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \ kong:latest kong migrations up
In the above example, both Cassandra and PostgreSQL are configured, but you should update the
KONG_DATABASE
environment variable with eithercassandra
orpostgres
.Note: migrations should never be run concurrently; only one Kong node should be performing migrations at a time.
-
Start Kong
When the migrations have run and your database is ready, start a Kong container that will connect to your database container, just like the ephemeral migrations container:
$ docker run -d --name kong \ --network=kong-net \ -e "KONG_DATABASE=postgres" \ -e "KONG_PG_HOST=kong-database" \ -e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \ -e "KONG_PROXY_ACCESS_LOG=/dev/stdout" \ -e "KONG_ADMIN_ACCESS_LOG=/dev/stdout" \ -e "KONG_PROXY_ERROR_LOG=/dev/stderr" \ -e "KONG_ADMIN_ERROR_LOG=/dev/stderr" \ -e "KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl" \ -p 8000:8000 \ -p 8443:8443 \ -p 8001:8001 \ -p 8444:8444 \ kong:0.13.1-centos
-
Use Kong
Kong is running:
$ curl -i http://localhost:8001/
Using Docker
# Start Kong Dashboard
docker run --rm -p 8080:8080 pgbi/kong-dashboard start --kong-url http://kong:8001
# Start Kong Dashboard on a custom port
docker run --rm -p [port]:8080 pgbi/kong-dashboard start --kong-url http://kong:8001
# Start Kong Dashboard with basic auth
docker run --rm -p 8080:8080 pgbi/kong-dashboard start \
--kong-url http://kong:8001 \
--basic-auth user1=password1 user2=password2
# See full list of start options
docker run --rm -p 8080:8080 pgbi/kong-dashboard start --help
- Create bridge network
docker network create my-net
- Add Kong container to it
docker network connect my-net kong
- Provide network info when you run kong-dashboard
docker run --rm --network my-net -p 8080:8080 pgbi/kong-dashboard start --kong-url http://kong:8001

【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步