【问题标题】:how to run ory/hydra on docker with custom config hyda.yaml file如何使用自定义配置 hyda.yaml 文件在 docker 上运行 ory/hydra
【发布时间】:2021-11-24 11:46:15
【问题描述】:

如何使用自定义配置文件将 ory/hydra 作为 docker 容器运行。 是最好的运行方式还是提供环境变量更好。 需要帮助!!

【问题讨论】:

    标签: oauth-2.0 openid-connect


    【解决方案1】:

    我使用包含以下内容的 dockerfile:

    FROM oryd/hydra:latest
    
    COPY hydra.yml /home/ory/.hydra
    COPY hydra.yml /.hydra
    
    EXPOSE 4444 4445 5555
    

    只需要一份,但我不知道是哪份 :)
    您可以使用 env 运行。变量也是如此,但我更喜欢 yaml,它更容易

    【讨论】:

      【解决方案2】:

      除了上面提到的解决方案,你也可以试试Docker Compose。就个人而言,我更喜欢这个,因为我发现它很容易跟踪和管理。

      官方5分钟教程也使用Docker Compose,可以在这里找到:https://www.ory.sh/hydra/docs/5min-tutorial/

      我在这里使用 PostgreSQL 作为数据库,但您可以将其替换为任何其他受支持的数据库,例如 MySQL。

      关于支持的数据库配置的更多信息在这里:https://www.ory.sh/hydra/docs/dependencies-environment/#database-configuration

      首先,您创建docker-compose.yml,如下所示,然后创建docker-compose up

      version: '3.7'
      
      networks:
        intranet:
          driver: bridge
      
      services:
        hydra-migrate:
          depends_on:
            - auth-db
          container_name: hydra-migrate
          image: oryd/hydra:v1.10.6
          environment:
            - DSN=postgres://auth:secret@auth-db:5432/auth?sslmode=disable&max_conns=20&max_idle_conns=4
          command: migrate sql -e --yes
          networks:
            - intranet
      
        hydra:
          container_name: hydra
          image: oryd/hydra:v1.10.6
          depends_on:
            - auth-db
            - hydra-migrate
          ports:
            - "4444:4444" # Public port
            - "4445:4445" # Admin port
            - "5555:5555" # Port for hydra token user
          command:
            serve -c /etc/hydra/config/hydra.yml all --dangerous-force-http
          restart: on-failure
          networks:
            - intranet
          volumes:
            - type: bind
              source: ./config
              target: /etc/hydra/config
      
        auth-db:
          image: postgres:alpine
          container_name: auth-db
          ports:
            - "5432:5432"
          environment:
            - POSTGRES_USER=auth
            - POSTGRES_PASSWORD=secret
            - POSTGRES_DB=auth
          networks:
            - intranet
      

      hydra-migrate 服务负责数据库迁移,我们实际上不需要为此指定外部配置文件,只需将 DSN 作为环境变量就足够了。

      hydra 服务启动了 hydra 容器,在这里我完成了卷挂载,我将本地 config 文件夹绑定到容器内的 /etc/hydra/config

      然后当容器启动时执行以下命令 serve -c /etc/hydra/config/hydra.yml all --dangerous-force-http 使用绑定的配置文件。

      这是我的 hydra 配置文件的样子:

      ## ORY Hydra Configuration
      version: v1.10.6
      
      serve:
        public:
          cors:
            enabled: true
      
      dsn: postgres://auth:secret@auth-db:5432/auth?sslmode=disable&max_conns=20&max_idle_conns=4
      
      oidc:
        subject_identifiers:
          supported_types:
            - public
            - pairwise
          pairwise:
            salt: youReallyNeedToChangeThis
      
      urls:
        login: http://localhost:4455/auth/login
        consent: http://localhost:4455/auth/consent
        logout: http://localhost:4455/consent
        error: http://localhost:4455/error
        post_logout_redirect: http://localhost:3000/
        self:
          public: http://localhost:4444/
          issuer: http://localhost:4444/
      
      ttl:
        access_token: 1h
        refresh_token: 1h
        id_token: 1h
        auth_code: 1h
      
      oauth2:
        expose_internal_errors: true
      
      secrets:
        cookie:
          - youReallyNeedToChangeThis
        system:
          - youReallyNeedToChangeThis
      
      log:
        leak_sensitive_values: true
        format: json
        level: debug
      

      【讨论】:

        猜你喜欢
        • 2021-04-01
        • 2015-07-20
        • 2020-02-25
        • 2023-01-16
        • 2021-04-03
        • 1970-01-01
        • 1970-01-01
        • 2011-09-07
        • 1970-01-01
        相关资源
        最近更新 更多