skip to Main Content

I’m doing a graduation project, and I’m about to put my project up to the server, but I’m having trouble with docker-compose.yml and Dockerfile files, could you please advise me where I should fix it?

How to fix this error?
nginx: [error] init_by_lua error: /usr/local/share/lua/5.1/kong/cmd/utils/migrations.lua:16: Database needs bootstrapping or is older than Kong 1.0.
To start a new installation from scratch, run ‘kong migrations bootstrap’.
To migrate from a version older than 1.0, migrated to Kong 1.5.0 first.
If you still have ‘apis’ entities, you can convert them to Routes and Services
using the ‘kong migrations migrate-apis’ command in Kong 1.5.0.
stack traceback:
[C]: in function ‘error’
/usr/local/share/lua/5.1/kong/cmd/utils/migrations.lua:16: in function ‘check_state’
/usr/local/share/lua/5.1/kong/init.lua:562: in function ‘init’
init_by_lua:3: in main chunk

dockerfile files

FROM python:3.10
 
WORKDIR /app
 
COPY requirements.txt .
RUN pip install -r requirements.txt
 
EXPOSE 8000
CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]

docker-compose files

version: '3.9'
services:
  kong-database:
    image: postgres:latest
    container_name: kong-database
    restart: always
    ports:
      - 15432:5432
    networks:
      - default
    volumes:
      - db:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=kong
      - POSTGRES_USER=kong
      - POSTGRES_PASSWORD=kong

  kong:
    image: kong:latest
    container_name: kong
    restart: always
    ports:
      - 18000:8000
      - 18443:8443
      - 127.0.0.1:8001:8001
      - 18444:8444
    links:
      - kong-database:kong-database
    networks:
      - default
    environment:
      - LC_CTYPE=en_US.UTF-8
      - LC_ALL=en_US.UTF-8
      - 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:18001, 0.0.0.0:18444 ssl
    
  konga:
    image: pantsel/konga
    container_name: kong-konga
    restart: always
    ports:
      - 1337:1337
    networks:
      - default
    volumes:
      - data:/app/kongadata
    links:
      - kong:kong
    environment:
      - NODE_ENV=production

networks:
  default:
    driver: bridge

volumes:
  db:
    driver: local
  data:
    driver: local

setting.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'kong',
        'USER': 'kong',
        'PASSWORD': 'kong',
        'HOST': '127.0.0.1',
        'PORT': '15432',
    }
}

2

Answers


  1. Consider running required migration process before launching pythong? E.g.

    CMD ["kong", "migrations bootstrap && python3 manage.py runserver 0.0.0.0:8000"]
    
    Login or Signup to reply.
  2. Database needs bootstrapping or is older than Kong 1.0. To start a new installation from scratch, run ‘kong migrations bootstrap’. To migrate from a version older than 1.0, migrated to Kong 1.5.0 first. If you still have ‘apis’ entities, you can convert them to Routes and Services using the ‘kong migrations migrate-apis’ command in Kong 1.5.0.

    The error comes from Kong not being able to use the database provided. when you bringing up kong there need to be an additional step of migrations/bootstrap to prepare the database to be used by Kong.

    Since you are using Docker Compose to bring the whole environment up, adding an additional container to do the migration first should be sufficient:

    kong-migrations:
        container_name: kong-migrations
        image: kong:latest
        environment:
          - KONG_DATABASE=postgres
          - KONG_PG_HOST=kong-database
          - KONG_PG_USER=kong
          - KONG_PG_PASSWORD=kong
          - KONG_PASSWORD=kong
        networks:
          - default
        command: kong migrations bootstrap
        depends_on:
          - kong-database
    

    Since you are mounting data volume from/to Kong database, the first run might not work since Kong might start before the migrations finish. If that’s the case, simply wait for Kong to restart automatically and it should work.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search