我在这里添加了我的 docker compose 文件以供参考
keycloak:
image: quay.io/keycloak/keycloak:20.0.0
container_name: keycloak
command:
[
"start-dev",
"--http-port=8081",
"--http-relative-path=/auth"
]
ports:
- "8081:8081"
environment:
- KEYCLOAK_ADMIN=admin
- KEYCLOAK_ADMIN_PASSWORD=admin1234
- KC_DB=postgres
- KC_DB_URL=jdbc:postgresql://postgresdb:5432/keycloak
- KC_DB_USERNAME=postgres
- KC_DB_PASSWORD=postgres
我在此页面上包含了一个 Docker Compose 文件供您参考。我在生产模式下运行 Keycloak 时遇到问题。你能帮我吗?
我想告诉你一件事,当我在 docker compose 文件中进行更改(例如“start”命令或卷)时,keycloak 容器会启动,然后在一段时间后退出。
您可以在这里找到解决方案:https://www.keycloak.org/server/containers
如您所见,您必须使用您的配置创建图像:
Dockerfile
FROM quay.io/keycloak/keycloak:latest as builder
# Enable health and metrics support
ENV KC_HEALTH_ENABLED=true
ENV KC_METRICS_ENABLED=true
# Configure a database vendor
ENV KC_DB=postgres
# Access data
ENV KEYCLOAK_ADMIN=admin
ENV KEYCLOAK_ADMIN_PASSWORD=admin1234
#you need an hostname in production mode! set it right or you will have infinite Console loading.
ENV KC_HOSTNAME=localhost
#relative path
ENV KC_HTTP_RELATIVE_PATH=/auth
#http port
ENV KC_HTTP_PORT= 8081
WORKDIR /opt/keycloak
# for demonstration purposes only, please make sure to use proper certificates in production instead
RUN keytool -genkeypair -storepass password -storetype PKCS12 -keyalg RSA -keysize 2048 -dname "CN=server" -alias server -ext "SAN:c=DNS:localhost,IP:127.0.0.1" -keystore conf/server.keystore
RUN /opt/keycloak/bin/kc.sh build
FROM quay.io/keycloak/keycloak:latest
COPY --from=builder /opt/keycloak/ /opt/keycloak/
# change these values to point to a running postgres instance
ENV KC_DB=postgres
ENV KC_DB_URL=jdbc:postgresql://postgresdb:5432/keycloak
ENV KC_DB_USERNAME=postgres
ENV KC_DB_PASSWORD=postgres
ENTRYPOINT ["/opt/keycloak/bin/kc.sh"]
构建此 Docker 文件:
docker build . -t mykeycloak
之后你就可以在 docker-compose 中运行镜像了:
keycloak:
image: mykeycloak
container_name: keycloak
command:
[
"start-dev",
"--optimized",
]
ports:
- "8081:8081"