作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在努力学习如何使用 Kong对于我的 API 服务器,但遇到错误:
kong_1 | nginx: [error] init_by_lua error: /usr/local/share/lua/5.1/kong/init.lua:388: [PostgreSQL error] failed to retrieve PostgreSQL server_version_num: host or service not provided, or not known
我的 docker-compose.yaml 如下:
version: "3"
networks:
kong-net:
driver: bridge
services:
# Create a service named db.
kong-postgres:
# Use the Docker Image postgres. This will pull the newest release.
image: "postgres"
# Give the container a name. You can changes to something else.
container_name: "kong-postgres"
# Setup the username, password, and database name. You can changes these values.
environment:
- POSTGRES_USER=kong
- POSTGRES_PASSWORD=kong
- POSTGRES_DB=kong
# Maps port 54320 (localhost) to port 5432 on the container. You can change the ports to fix your needs.
ports:
- "5432:5432"
restart: on-failure
# Set a volume some that database is not lost after shutting down the container.
# I used the name postgres-data but you can changed it to something else.
volumes:
- ./postgres-data:/var/lib/postgresql/data
kong:
image: "kong:latest"
command: "kong migrations bootstrap"
depends_on:
- kong-postgres
environment:
KONG_ADMIN_LISTEN: '0.0.0.0:8001,0.0.0.0:8444 ssl'
KONG_DATABASE: postgres
KONG_PG_HOST: kong-postgres
KONG_PG_DATABASE: kong
KONG_PG_PASSWORD: kong
KONG_PG_USER: kong
networks:
- kong-net
ports:
- "8000:8000/tcp"
- "8001:8001/tcp"
- "8443:8443/tcp"
- "8444:8444/tcp"
healthcheck:
test: ["CMD", "kong", "health"]
interval: 10s
timeout: 10s
retries: 10
restart: on-failure
还尝试分两步运行它:
docker-compose up kong-postgres
,没问题: $ docker-compose up kong-postgres
Starting kong-postgres ... done
Attaching to kong-postgres
kong-postgres |
kong-postgres | PostgreSQL Database directory appears to contain a database; Skipping initialization
kong-postgres |
kong-postgres | 2019-11-20 08:22:37.057 UTC [1] LOG: starting PostgreSQL 12.1 (Debian 12.1-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
kong-postgres | 2019-11-20 08:22:37.057 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
kong-postgres | 2019-11-20 08:22:37.057 UTC [1] LOG: listening on IPv6 address "::", port 5432
kong-postgres | 2019-11-20 08:22:37.060 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
kong-postgres | 2019-11-20 08:22:37.128 UTC [25] LOG: database system was shut down at 2019-11-20 08:08:28 UTC
kong-postgres | 2019-11-20 08:22:37.176 UTC [1] LOG: database system is ready to accept connections
数据库可以通过psql -h localhost -p 5432 -U kong -d kong
连接:
$ psql -h localhost -p 5432 -U kong -d kong
Password for user kong:
psql (11.5, server 12.1 (Debian 12.1-1.pgdg100+1))
WARNING: psql major version 11, server major version 12.
Some psql features might not work.
Type "help" for help.
kong=# \q
docker-compose up kong
失败: $ docker-compose up kong
kong-postgres is up-to-date
Recreating kong_kong_1 ... done
Attaching to kong_kong_1
kong_1 | Error: [PostgreSQL error] failed to retrieve PostgreSQL server_version_num: host or service not provided, or not known
kong_1 |
kong_1 | Run with --v (verbose) or --vv (debug) for more details
附:official Docker Compose template也失败了:
kong-migrations-up_1 | Error: Cannot run migrations: database needs bootstrapping; run 'kong migrations bootstrap'
kong-migrations-up_1 |
kong-migrations-up_1 | Run with --v (verbose) or --vv (debug) for more details
最佳答案
version: "3.7"
volumes:
kong_data: {}
networks:
kong-net:
services:
#######################################
# Postgres: The database used by Kong
#######################################
kong-database:
image: postgres:9.6
container_name: kong-postgres
restart: on-failure
networks:
- kong-net
volumes:
- kong_data:/var/lib/postgresql/data
environment:
POSTGRES_USER: kong
POSTGRES_PASSWORD: ${KONG_PG_PASSWORD:-kong}
POSTGRES_DB: kong
ports:
- "5432:5432"
healthcheck:
test: ["CMD", "pg_isready", "-U", "kong"]
interval: 30s
timeout: 30s
retries: 3
#######################################
# Kong database migration
#######################################
kong-migration:
image: ${KONG_DOCKER_TAG:-kong:latest}
command: kong migrations bootstrap
networks:
- kong-net
restart: on-failure
environment:
KONG_DATABASE: postgres
KONG_PG_HOST: kong-database
KONG_PG_DATABASE: kong
KONG_PG_USER: kong
KONG_PG_PASSWORD: ${KONG_PG_PASSWORD:-kong}
depends_on:
- kong-database
#######################################
# Kong: The API Gateway
#######################################
kong:
image: ${KONG_DOCKER_TAG:-kong:latest}
restart: on-failure
networks:
- kong-net
environment:
KONG_DATABASE: postgres
KONG_PG_HOST: kong-database
KONG_PG_DATABASE: kong
KONG_PG_USER: kong
KONG_PG_PASSWORD: ${KONG_PG_PASSWORD:-kong}
KONG_PROXY_LISTEN: 0.0.0.0:8000
KONG_PROXY_LISTEN_SSL: 0.0.0.0:8443
KONG_ADMIN_LISTEN: 0.0.0.0:8001
depends_on:
- kong-database
healthcheck:
test: ["CMD", "kong", "health"]
interval: 10s
timeout: 10s
retries: 10
ports:
- "8000:8000"
- "8001:8001"
- "8443:8443"
- "8444:8444"
#######################################
# Konga database prepare
#######################################
konga-prepare:
image: pantsel/konga:latest
command: "-c prepare -a postgres -u postgresql://kong:${KONG_PG_PASSWORD:-kong}@kong-database:5432/konga"
networks:
- kong-net
restart: on-failure
depends_on:
- kong-database
#######################################
# Konga: Kong GUI
#######################################
konga:
image: pantsel/konga:latest
restart: always
networks:
- kong-net
environment:
DB_ADAPTER: postgres
DB_URI: postgresql://kong:${KONG_PG_PASSWORD:-kong}@kong-database:5432/konga
NODE_ENV: production
depends_on:
- kong-database
ports:
- "1337:1337"
关于docker-compose - Kong:docker-compose [PostgreSQL 错误] 检索 PostgreSQL server_version_num 失败:未提供主机或服务,或未知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58950647/
我目前正在运行 Docker 19.03.5 并尝试复制 this article 的内容,但我在第三步中收到以下错误: 第一步: docker network create kong-net 二:
我正在努力学习如何使用 Kong对于我的 API 服务器,但遇到错误: kong_1 | nginx: [error] init_by_lua error: /usr/local/
我是一名优秀的程序员,十分优秀!