参考地址: https://docs.konghq.com/gateway/2.6.x/install-and-run/docker/

遇事不决, 先关闭防火墙

不要问我为什么, 因为如果不关, 后面配置docker网络的时候会有很多问题
systemctl stop firewalld

1.拉取镜像

docker pull kong/kong-gateway:2.6.0.1-alpine

2.tag镜像

docker tag kong/kong-gateway:2.6.0.1-alpine 你的镜像名

3.新建一个docker网络

docker network create 一个网络名

4.安装postgresql

  1. docker run -d --name postgresql名称 \
  2. --network=一个网络名 \
  3. -p 5432:5432 \
  4. -e "POSTGRES_USER=kong" \
  5. -e "POSTGRES_DB=kong" \
  6. -e "POSTGRES_PASSWORD=kong" \
  7. postgres:9.6

5.为kong配置数据库

  1. docker run --rm --network=一个网络名 \
  2. -e "KONG_DATABASE=postgres" \
  3. -e "KONG_PG_HOST=postgresql名称" \
  4. -e "KONG_PG_PASSWORD=kong" \
  5. -e "KONG_PASSWORD=kong的密码(不是数据库的密码, 这个密码我也不知道是用来干嘛的)" \
  6. {TAG_NAME} {DATABASE_NAME} migrations bootstrap

6.启动kong

  1. docker run -d --name kong的容器名 \
  2. --network=一个网络名 \
  3. -e "KONG_DATABASE=postgres" \
  4. -e "KONG_PG_HOST=192.168.4.111(本地的postgresql地址)" \
  5. -e "KONG_PG_USER=kong" \
  6. -e "KONG_PG_PASSWORD=kong" \
  7. -e "KONG_PROXY_ACCESS_LOG=/dev/stdout" \
  8. -e "KONG_ADMIN_ACCESS_LOG=/dev/stdout" \
  9. -e "KONG_PROXY_ERROR_LOG=/dev/stderr" \
  10. -e "KONG_ADMIN_ERROR_LOG=/dev/stderr" \
  11. -e "KONG_ADMIN_LISTEN=0.0.0.0:8001" \
  12. -e "KONG_ADMIN_GUI_URL=http://192.168.4.111:8002" \
  13. -p 8000:8000 \
  14. -p 8443:8443 \
  15. -p 8001:8001 \
  16. -p 8444:8444 \
  17. -p 8002:8002 \
  18. -p 8445:8445 \
  19. -p 8003:8003 \
  20. -p 8004:8004 \
  21. 你的镜像名

到这里就安装成功了
可以通过以下命令检查, 如果返回200说明kong安装成功了

  1. curl -i -X GET --url http://192.168.4.111:8001/services

image.png

在konga中添加kong

image.png

也可以通过8002端口进行管理(不推荐)

image.png