File tree 1 file changed +23
-0
lines changed
1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,20 @@ import (
13
13
"gopkg.in/gin-contrib/cors.v1"
14
14
)
15
15
16
+ func isRunningInDockerContainer () bool {
17
+ // slightly modified from blog: https://paulbradley.org/indocker/
18
+ // docker creates a .dockerenv file at the root
19
+ // of the directory tree inside the container.
20
+ // if this file exists then the viewer is running
21
+ // from inside a container so return true
22
+
23
+ if _ , err := os .Stat ("/.dockerenv" ); err == nil {
24
+ return true
25
+ }
26
+
27
+ return false
28
+ }
29
+
16
30
// StartAPIServer starts the API server
17
31
func StartAPIServer (config * Config ,
18
32
reloadChan chan bool ,
@@ -23,6 +37,15 @@ func StartAPIServer(config *Config,
23
37
}
24
38
25
39
router := gin .Default ()
40
+
41
+ // Automatically replace the default listening address in the docker with `0.0.0.0`
42
+ if isRunningInDockerContainer () {
43
+ const localhost = "127.0.0.1:"
44
+ if strings .HasPrefix (config .API , localhost ) {
45
+ config .API = strings .Replace (config .API , localhost , "0.0.0.0:" , 1 )
46
+ }
47
+ }
48
+
26
49
server := & http.Server {
27
50
Addr : config .API ,
28
51
Handler : router ,
You can’t perform that action at this time.
0 commit comments