version: "3"
services:
postgres:
container_name: pgsql
image: postgres:15
ports:
- "5432:5432"
volumes:
- ./database-data:/var/lib/postgresql/data
healthcheck:
test: ["CMD", "pg_isready", "-U", "user"]
interval: 30s
timeout: 20s
retries: 3
environment:
POSTGRES_USER: 'keycloak'
POSTGRES_PASSWORD: '<pgsql数据库密码>'
POSTGRES_DB: 'keycloak'
TZ: Asia/Shanghai
keycloak:
image: quay.io/keycloak/keycloak:23.0
container_name: keycloak
environment:
KC_HOSTNAME: <域名,如sso.naizhao.com>
KC_HTTP_PORT: <监听的http端口,比如8080>
KC_HTTPS_PORT: <监听的http端口,比如8443>
KC_HOSTNAME_STRICT_HTTPS: true
KC_FEATURES: token-exchange
KC_DB: postgres
KC_DB_URL: jdbc:postgresql://<pgsql的IP,比如127.0.0.1>:5432/keycloak
KC_DB_USERNAME: keycloak
KC_DB_PASSWORD: <前面创建pgsql账号时输入的密码>
KEYCLOAK_ADMIN: <管理员账号,比如admin>
KEYCLOAK_ADMIN_PASSWORD: <管理员密码>
KC_HEALTH_ENABLED: "true"
KC_LOG_LEVEL: info
KC_PROXY: edge
healthcheck:
test: [ "CMD", "curl", "-f", "http://localhost:8080/health/ready" ]
interval: 15s
timeout: 2s
retries: 15
command: start
ports:
# 这里把8080端口映射到10080,8443映射到10443,防止和服务器上其他端口冲突
- 10080:8080
- 10443:8443