본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Docker Compose로 Kong Gateway 설치

원문 보기 위키 갱신

Docker Compose로 Kong Gateway 설치 (Install Kong Gateway using Docker Compose)

Docker Compose를 사용하면 복잡한 설정 없이 Kong Gateway를 손쉽게 띄울 수 있어요. 이 문서에서는 docker-compose.yml 파일을 만들고 Postgres 데이터베이스와 함께 Kong Gateway 컨테이너를 구성한 뒤 실행하고 검증하는 과정을 단계별로 안내해요. 명령어 몇 줄로 설치부터 정리까지 전체 흐름을 따라 할 수 있어서 처음 Kong Gateway를 설치하는 분들께 특히 좋아요

출처: 문서

본문

TL;DR

Docker Compose로 Kong Gateway를 어떻게 설치하나요? 예제 Docker Compose 파일을 만들고 docker compose up -d를 실행해요.

사전 준비

Docker Compose

이 가이드를 사용하려면 시스템에 Docker가 설치되어 있어야 해요.

Docker Compose 파일 설정하기

다음 명령어를 실행해서 docker-compose.yml 파일을 생성하고, 3.16.0.0은 본인이 사용하는 Kong Gateway 버전으로 바꿔세요:

cat <<EOF > docker-compose.yml

volumes:
  kong_db_data: {}  # Named volume to persist Postgres data across container restarts

networks:
  kong-ee-net:      # Custom bridge network for isolated Kong and Postgres communication
    driver: bridge

# Common environment variables used by Kong services (bootstrap and CP)
x-kong-config: &kong-env
  KONG_DATABASE: postgres             # Use Postgres as the backing database
  KONG_PG_HOST: kong-ee-database      # Hostname of the Postgres service
  KONG_PG_DATABASE: kong              # Name of the database to connect to
  KONG_PG_USER: kong                  # Database username
  KONG_PG_PASSWORD: kong              # Database password
  KONG_LICENSE_DATA: "\${KONG_LICENSE_DATA}"  # Kong Enterprise license passed via environment variable

services:

  kong-ee-database:
    container_name: kong-ee-database
    image: postgres:latest           # Official Postgres image
    restart: on-failure              # Restart if the container fails
    volumes:
      - kong_db_data:/var/lib/postgresql  # Mount the volume for persistent data
    networks:
      - kong-ee-net                  # Connect to the shared Kong network
    environment:
      POSTGRES_USER: kong            # Set DB user inside the container
      POSTGRES_DB: kong              # Create this database on first run
      POSTGRES_PASSWORD: kong        # Set the password for the DB user
    healthcheck:                     # Ensure the DB is ready before starting dependent services
      test: ["CMD", "pg_isready", "-U", "kong"]
      interval: 5s
      timeout: 10s
      retries: 10
    ports:
      - '5432:5432'                  # Optional: expose Postgres on localhost for debugging

  kong-bootstrap:
    image: '${GW_IMAGE:-kong/kong-gateway:3.16.0.0}'  # Kong Gateway image (default to latest version)
    container_name: kong-bootstrap
    networks:
      - kong-ee-net
    depends_on:
      kong-ee-database:
        condition: service_healthy   # Wait until Postgres is up and healthy
    restart: on-failure
    environment:
      <<: *kong-env                 # Reuse environment config from x-kong-config
      KONG_PASSWORD: handyshake    # Admin GUI password (required for RBAC)
    command: kong migrations bootstrap  # Run DB migrations to initialize Kong schema

  kong-cp:
    image: '${GW_IMAGE:-kong/kong-gateway:3.16.0.0}'  # Main Kong Gateway Control Plane (default to latest version)
    container_name: kong-cp
    restart: on-failure
    networks:
      - kong-ee-net
    environment:
      <<: *kong-env
      KONG_ADMIN_LISTEN: 0.0.0.0:8001, 0.0.0.0:8444 ssl  # Admin API on HTTP + HTTPS
      KONG_ADMIN_GUI_LISTEN: 0.0.0.0:8002, 0.0.0.0:8445 ssl  # Kong Manager on HTTP + HTTPS
      KONG_ADMIN_GUI_URL: http://${GW_HOST:-localhost}:8002  # URL for GUI links
      KONG_PASSWORD: handyshake  # Required for logging in to Kong Manager (RBAC)
    depends_on:
      kong-bootstrap:
        condition: service_completed_successfully  # Start only after bootstrap has succeeded
    ports:
      - "8000:8000"  # Proxy HTTP
      - "8443:8443"  # Proxy HTTPS
      - "8001:8001"  # Admin API HTTP
      - "8444:8444"  # Admin API HTTPS
      - "8002:8002"  # Kong Manager HTTP
      - "8445:8445"  # Kong Manager HTTPS
EOF

Kong Gateway 시작하기

Docker Compose 파일로 Kong Gateway를 시작해요:

docker compose up -d

검증

Kong Gateway Admin API에 cURL로 요청을 보내서 Kong Gateway가 실행 중인지 확인할 수 있어요:

curl -X GET "http://localhost:8001/" \
     --no-progress-meter --fail-with-body 

그러면 HTTP/1.1 200 OK 응답이 반환돼요.

정리

Kong Gateway 컨테이너 삭제하기

docker compose down

FAQ

  • Kong Gateway를 읽기 전용 모드로 실행할 수 있나요? 네, database를 off로 설정하고 컨테이너를 시작할 때 설정 파일을 전달하면 Kong Gateway Docker 컨테이너를 읽기 전용 모드로 실행할 수 있어요. 자세한 내용은 Docker Compose로 Kong Gateway를 읽기 전용 모드로 실행하기를 참고하세요.

관련 리소스

더 알아보기 (Learn more)