Kong:docker-compose [PostgreSQL错误]无法检索PostgreSQL server_version_num:未提供或未知的主机或服务 [英] Kong: docker-compose [PostgreSQL error] failed to retrieve PostgreSQL server_version_num: host or service not provided, or not known

查看:152
本文介绍了Kong:docker-compose [PostgreSQL错误]无法检索PostgreSQL server_version_num:未提供或未知的主机或服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习如何为我的API服务器使用 Kong ,但是遇到了错误:

I'm trying to learn how to use Kong for my API server, but met the error:

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如下:

My docker-compose.yaml as below:

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

还尝试通过2个步骤运行它:

Also tried running it by 2 steps:

  1. docker-commit 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

  1. 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

ps:官方Docker Compose模板也失败了:

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"

这篇关于Kong:docker-compose [PostgreSQL错误]无法检索PostgreSQL server_version_num:未提供或未知的主机或服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆