From 1ec81f35c0fe24c4da03b533eac1b7fe294e3c75 Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Sat, 2 Dec 2023 02:25:05 -0300 Subject: [PATCH] allow remote api calls if inside a docker container --- local/network.go | 10 ++++++++++ utils/utils.go | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/local/network.go b/local/network.go index 7012752a..15cc1bb2 100644 --- a/local/network.go +++ b/local/network.go @@ -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) diff --git a/utils/utils.go b/utils/utils.go index f527afc0..7eb1bc28 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -18,6 +18,7 @@ import ( const ( genesisNetworkIDKey = "networkID" dirTimestampFormat = "20060102_150405" + dockerEnvPath = "/.dockerenv" ) var ( @@ -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 +}