Skip to content

Commit 7355657

Browse files
authored
run docker with yaml config file (#207)
1 parent 7cb8cb5 commit 7355657

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,17 @@ docker run \
10131013
timothyye/godns:latest
10141014
```
10151015

1016+
To run it with a `YAML` config file:
1017+
1018+
```bash
1019+
docker run \
1020+
-d --name godns \
1021+
-e CONFIG=/config.yaml \
1022+
--restart=always \
1023+
-v /path/to/config.yaml:/config.yaml \
1024+
timothyye/godns:latest
1025+
```
1026+
10161027
### As a Windows service
10171028

10181029
1. Download the latest version of [NSSM](https://nssm.cc/download)

cmd/godns/godns.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import (
1414
"github.com/fatih/color"
1515
)
1616

17+
const (
18+
configEnv = "CONFIG"
19+
)
20+
1721
var (
1822
configuration settings.Settings
1923
optConf = flag.String("c", "./config.json", "Specify a config file")
@@ -28,15 +32,24 @@ func init() {
2832
}
2933

3034
func main() {
35+
3136
flag.Parse()
3237
if *optHelp {
3338
color.Cyan(utils.Logo, Version)
3439
flag.Usage()
3540
return
3641
}
3742

43+
configPath := *optConf
44+
45+
// read config path from the environment
46+
if os.Getenv(configEnv) != "" {
47+
// overwrite the config path
48+
configPath = os.Getenv(configEnv)
49+
}
50+
3851
// Load settings from configurations file
39-
if err := settings.LoadSettings(*optConf, &configuration); err != nil {
52+
if err := settings.LoadSettings(configPath, &configuration); err != nil {
4053
log.Fatal(err)
4154
}
4255

0 commit comments

Comments
 (0)