donglue1886 2019-08-19 14:57
浏览 182

如何将配置文件推送到新的oryd / hydra docker映像?

I am using the oryd/hydra docker image: https://hub.docker.com/r/oryd/hydra in order to build a custom image with my own configuration.

I did create a custom directory:

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

then I create a Dockerfile using that syntax:

vi Dockerfile

the file content:

$ cat Dockerfile

FROM oryd/hydra:latest

COPY .hydra /

when building the image I get no error:

$ docker build -t sso-demo-hydra .

Sending build context to Docker daemon 8.704kB

Step 1/2 : FROM oryd/hydra:latest

---> 50f0a70dbda9

Step 2/2 : COPY .hydra /

---> Using cache

---> 3539634979c0

Successfully built 3539634979c0

Successfully tagged sso-demo-hydra:latest

SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.

And when I launch the application I get the following warning:

sso-demo-hydra | Config file not found because "Config File ".hydra" Not Found in "[/]""

PS: there is a .hydra file in the context directory

Thanks for your support.

  • 写回答

1条回答

  • dongyun6003 2019-08-20 02:04
    关注

    See github source code of this docker image, the related code is as next:

    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("")
        }
    }
    

    From above, you can see in fact what it expected is .hydra.yml, not .hydra, .hydra just the one which remove extension:

    viper.SetConfigName(".hydra") // name of config file (without extension)

    So the root cause is: its error indication not friendly which make you encountered problem, change to use .hydra.yml could make it ok.

    评论

报告相同问题?