【问题标题】:How to push config file to new oryd/hydra docker image?如何将配置文件推送到新的 oryd/hydra docker 镜像?
【发布时间】:2019-08-19 14:57:10
【问题描述】:

我正在使用 oryd/hydra docker 镜像:https://hub.docker.com/r/oryd/hydra 为了使用我自己的配置构建自定义图像。

我确实创建了一个自定义目录:

mkdir sso-demo-hydra
cd sso-demo-hydra

然后我使用该语法创建一个 Dockerfile:

vi Dockerfile

文件内容:

$ cat Dockerfile

来自 oryd/hydra:最新

复制.hydra /

在构建图像时我没有收到任何错误:

$ docker build -t sso-demo-hydra .

将构建上下文发送到 Docker 守护进程 8.704kB

第 1/2 步:来自 oryd/hydra:latest

---> 50f0a70dbda9

第 2/2 步:复制 .hydra /

--->使用缓存

---> 3539634979c0

构建成功3539634979c0

成功标记 sso-demo-hydra:latest

安全警告:您正在针对非 Windows Docker 主机从 Windows 构建 Docker 映像。添加到构建上下文的所有文件和目录都将具有“-rwxr-xr-x”权限。建议仔细检查并重置敏感文件和目录的权限。

当我启动应用程序时,我收到以下警告:

sso-demo-hydra |未找到配置文件,因为“[/]”中未找到“配置文件”.hydra”

PS:上下文目录中有一个.hydra文件

感谢您的支持。

【问题讨论】:

    标签: docker go dockerfile


    【解决方案1】:

    查看这个docker镜像的github source code,相关代码如下:

    func initConfig() {
        if cfgFile != "" {
            // enable ability to specify config file via flag
            viper.SetConfigFile(cfgFile)
        } else {
            path := absPathify("$HOME")
            if _, err := os.Stat(filepath.Join(path, ".hydra.yml")); err != nil {
                _, _ = os.Create(filepath.Join(path, ".hydra.yml"))
            }
    
            viper.SetConfigType("yaml")
            viper.SetConfigName(".hydra") // name of config file (without extension)
            viper.AddConfigPath("$HOME")  // adding home directory as first search path
        }
    
        viper.SetDefault("LOG_LEVEL", "info")
    
        viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
        viper.AutomaticEnv() // read in environment variables that match
    
        // If a config file is found, read it in.
        if err := viper.ReadInConfig(); err != nil {
            fmt.Printf(`Config file not found because "%s"`, err)
            fmt.Println("")
        }
    }
    

    从上面,你可以看到实际上它所期望的是.hydra.yml,而不是.hydra.hydra 只是删除扩展的那个:

    viper.SetConfigName(".hydra") // 配置文件名(不带扩展名)

    所以根本原因是:它的错误提示不友好导致你遇到问题,改用.hydra.yml就可以了。

    【讨论】:

    • 感谢您的输入,无论如何我已经使用环境变量解决了这个问题。配置文件不是正确的方法
    【解决方案2】:

    在这种情况下,我建议您在启动 docker 容器时传递配置文件 (--config )。例如:

    docker run -d \
      --name ory-hydra-example--hydra \
      --network hydraguide \
      -p 9000:4444 \
      -p 9001:4445 \
      -e SECRETS_SYSTEM=$SECRETS_SYSTEM \
      -e DSN=$DSN \
      -e URLS_SELF_ISSUER=http://127.0.0.1:9000 \
      -e URLS_CONSENT=http://127.0.0.1:9020/consent \
      -e URLS_LOGIN=http://127.0.0.1:9020/login \
      -v $(pwd)/hydra.yaml:/hydra.yaml \
      oryd/hydra:v1.8.5 serve all --config hydra.yaml --dangerous-force-http
    

    这样您就不需要创建自己的 dockerfile。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-10
      • 2015-04-05
      • 2020-01-30
      • 2020-04-06
      相关资源
      最近更新 更多