Docker-compose卷无法保存Keycloak的容器状态

时间:2019-12-11 04:34:49

标签: docker docker-compose dockerfile keycloak docker-volume

docker-compose.yml

services:
  idprovider-app:
    container_name: idprovider-app
    build:
      dockerfile: Dockerfile
      context: .
    environment:
      KEYCLOAK_USER: admin
      KEYCLOAK_PASSWORD: admin
    volumes:
        - keycloak-data-volume:/var/lib/keycloak/data
    ports:
      - "8090:8090"   
      - "8443:8443"     
volumes:
  keycloak-data-volume:
    external: true

dockerfile

FROM jboss/keycloak:7.0.1
EXPOSE 8080
EXPOSE 8443

泊坞窗检查“容器”

"Mounts": [
            {
                "Type": "volume",
                "Name": "keycloak-data-volume",
                "Source": "/mnt/sda1/var/lib/docker/volumes/keycloak-data-volume/_data",
                "Destination": "/var/lib/keycloak/data",
                "Driver": "local",
                "Mode": "rw",
                "RW": true,
                "Propagation": ""
            }
        ],

docker volume inspect keycloak-data-volume

[
    {
        "CreatedAt": "2019-12-10T19:31:55Z",
        "Driver": "local",
        "Labels": {},
        "Mountpoint": "/mnt/sda1/var/lib/docker/volumes/keycloak-data-volume/_data",
        "Name": "keycloak-data-volume",
        "Options": {},
        "Scope": "local"
    }
]

没有错误,但不保存状态。我不知道怎么了我在Windows 10上运行它。

3 个答案:

答案 0 :(得分:0)

您使用哪个数据库?我认为您还需要将数据库卷与其绑定以保存状态。

例如:用于后退

services:
  postgres:
      image: postgres
      volumes:
        - postgres_data:/var/lib/postgresql/data
      environment:
        POSTGRES_DB: keycloak
        POSTGRES_USER: keycloak
        POSTGRES_PASSWORD: password

或用于mysql

services:
  mysql:
      image: mysql:5.7
      volumes:
        - mysql_data:/var/lib/mysql
      environment:
        MYSQL_ROOT_PASSWORD: root
        MYSQL_DATABASE: keycloak
        MYSQL_USER: keycloak
        MYSQL_PASSWORD: password

答案 1 :(得分:0)

您必须在环境变量中指定数据库的来源。 如果您对Postgres的PostgreSQL实例使用了其他服务,则必须在服务中指定DB_ADDR环境变量。

services:
  idprovider-app:
    container_name: idprovider-app
    build:
      dockerfile: Dockerfile
      context: .
    environment:
      DB_VENDOR: POSTGRES
      # Specify hostname of the database (eg: hostname or hostname:port)
      DB_ADDR: hostname:5432 
      DB_DATABASE: keycloak
      DB_USER: keycloak
      DB_SCHEMA: public
      DB_PASSWORD: password
      KEYCLOAK_USER: admin
      KEYCLOAK_PASSWORD: admin
    volumes:
        - keycloak-data-volume:/var/lib/keycloak/data
    ports:
      - "8090:8090"   
      - "8443:8443"     
volumes:
  keycloak-data-volume:
    external: true

答案 2 :(得分:0)

使用默认数据库位置,您可以通过 docker-compose 尝试此选项:

keycloak:
    image: quay.io/keycloak/keycloak:14.0.0
    container_name: keycloak
    environment:
      KEYCLOAK_USER: admin
      KEYCLOAK_PASSWORD: admin
    ports:
      - "8082:8080"
    restart: always
    volumes:
      - .local/keycloak/:/opt/jboss/keycloak/standalone/data/

用普通的 docker https://stackoverflow.com/a/60554189/6916890 找到了类似的答案

docker run --volume /root/keycloak/data/:/opt/jboss/keycloak/standalone/data/