Skip to content

Commit 5309eee

Browse files
authored
Merge pull request #687 from ava-labs/allow-remote-api-calls-on-container
allow remote api calls if inside a docker container
2 parents eba8fd4 + 27b6d31 commit 5309eee

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

local/network.go

+10
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,16 @@ func (ln *localNetwork) buildArgs(
11391139
config.BootstrapIDsKey: ln.bootstraps.IDsArg(),
11401140
}
11411141

1142+
insideContainer, err := utils.IsInsideDockerContainer()
1143+
if err != nil {
1144+
return buildArgsReturn{}, err
1145+
}
1146+
if insideContainer {
1147+
// mapped localhost requests (eg using -p flag of docker run) are seen as coming from an external IP like 172.17.0.1
1148+
// so inside docker container just accept all requests
1149+
flags[config.HTTPHostKey] = ""
1150+
}
1151+
11421152
// Write staking key/cert etc. to disk so the new node can use them,
11431153
// and get flag that point the node to those files
11441154
fileFlags, err := writeFiles(ln.networkID, ln.genesis, dataDir, nodeConfig)

utils/utils.go

+16
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
const (
1919
genesisNetworkIDKey = "networkID"
2020
dirTimestampFormat = "20060102_150405"
21+
dockerEnvPath = "/.dockerenv"
2122
)
2223

2324
var (
@@ -140,3 +141,18 @@ func VerifySubnetHasCorrectParticipants(
140141
}
141142
return false
142143
}
144+
145+
func IsInsideDockerContainer() (bool, error) {
146+
return PathExists(dockerEnvPath)
147+
}
148+
149+
func PathExists(path string) (bool, error) {
150+
_, err := os.Stat(path)
151+
if err != nil {
152+
if errors.Is(err, fs.ErrNotExist) {
153+
return false, nil
154+
}
155+
return false, err
156+
}
157+
return true, nil
158+
}

0 commit comments

Comments
 (0)