Skip to content

Commit

Permalink
run docker with yaml config file (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyYe authored May 13, 2023
1 parent 7cb8cb5 commit 7355657
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,17 @@ docker run \
timothyye/godns:latest
```

To run it with a `YAML` config file:

```bash
docker run \
-d --name godns \
-e CONFIG=/config.yaml \
--restart=always \
-v /path/to/config.yaml:/config.yaml \
timothyye/godns:latest
```

### As a Windows service

1. Download the latest version of [NSSM](https://nssm.cc/download)
Expand Down
15 changes: 14 additions & 1 deletion cmd/godns/godns.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (
"github.com/fatih/color"
)

const (
configEnv = "CONFIG"
)

var (
configuration settings.Settings
optConf = flag.String("c", "./config.json", "Specify a config file")
Expand All @@ -28,15 +32,24 @@ func init() {
}

func main() {

flag.Parse()
if *optHelp {
color.Cyan(utils.Logo, Version)
flag.Usage()
return
}

configPath := *optConf

// read config path from the environment
if os.Getenv(configEnv) != "" {
// overwrite the config path
configPath = os.Getenv(configEnv)
}

// Load settings from configurations file
if err := settings.LoadSettings(*optConf, &configuration); err != nil {
if err := settings.LoadSettings(configPath, &configuration); err != nil {
log.Fatal(err)
}

Expand Down

0 comments on commit 7355657

Please sign in to comment.