Skip to content

Commit

Permalink
allow remote api calls if inside a docker container
Browse files Browse the repository at this point in the history
  • Loading branch information
felipemadero committed Dec 2, 2023
1 parent 2f3ceed commit 1ec81f3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions local/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,16 @@ func (ln *localNetwork) buildArgs(
config.BootstrapIDsKey: ln.bootstraps.IDsArg(),
}

insideContainer, err := utils.InsideDockerContainer()
if err != nil {
return buildArgsReturn{}, err
}
if insideContainer {
// mapped localhost requests (eg using -p flag of docker run) are seen as coming from an external IP like 172.17.0.1
// so inside docker container just accept all requests
flags[config.HTTPHostKey] = ""
}

// Write staking key/cert etc. to disk so the new node can use them,
// and get flag that point the node to those files
fileFlags, err := writeFiles(ln.networkID, ln.genesis, dataDir, nodeConfig)
Expand Down
9 changes: 9 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
const (
genesisNetworkIDKey = "networkID"
dirTimestampFormat = "20060102_150405"
dockerEnvPath = "/.dockerenv"
)

var (
Expand Down Expand Up @@ -140,3 +141,11 @@ func VerifySubnetHasCorrectParticipants(
}
return false
}

func InsideDockerContainer() (bool, error) {
_, err := os.Stat(dockerEnvPath)
if err != nil {
return false, err
}
return true, nil
}

0 comments on commit 1ec81f3

Please sign in to comment.