Skip to content

Commit

Permalink
Fix container IP selection
Browse files Browse the repository at this point in the history
  • Loading branch information
mesudip committed Sep 26, 2024
1 parent e84ed0c commit 9e555cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
13 changes: 8 additions & 5 deletions nginx_proxy/WebServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ def learn_yourself(self):
self.id=self.container.id
networks = [a for a in self.container.attrs["NetworkSettings"]["Networks"].keys()]
for network in networks:
net_detail=self.client.networks.get(a)
self.networks[net_detail.id]=self.networks[net_detail.name]
self.networks[net_detail.name]=self.networks[net_detail.id]
print ("Check known network: ",network)
net_detail=self.client.networks.get(network)
self.networks[net_detail.id]=net_detail.name
self.networks[net_detail.name]=net_detail.id
except (KeyboardInterrupt, SystemExit) as e:
raise e
except Exception as e:
Expand All @@ -90,8 +91,10 @@ def learn_yourself(self):
"\n Is it running in docker environment?",
file=sys.stderr)
print("Falling back to default network", file=sys.stderr)
network = self.client.networks.get("frontend")
self.networks[network.id] = "frontend"
default_network="frontend"
network = self.client.networks.get(default_network)
self.networks[network.id] = default_network
self.networks[default_network] = network.id

def _register_container(self, container: DockerContainer):
"""
Expand Down
13 changes: 4 additions & 9 deletions nginx_proxy/pre_processors/virtual_host_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,11 @@ def host_generator(container: DockerContainer, service_id: str = None, known_net
unknown = True
for name, detail in network_settings["Networks"].items():
c.add_network(detail["NetworkID"])
# fix for https://trello.com/c/js37t4ld
if detail["Aliases"] is not None: # we might use alias
if detail["NetworkID"] in known_networks and unknown:
alias = detail["Aliases"][len(detail["Aliases"]) - 1]
ip_address = detail["IPAddress"]
network = name
if ip_address:
break
elif detail['NetworkID']:
if detail["NetworkID"] and detail["NetworkID"] in known_networks and unknown:
ip_address = detail["IPAddress"]
#if detail["Aliases"] is not None: # we might use alias
# alias = detail["Aliases"][len(detail["Aliases"]) - 1]
# network = name
if ip_address:
break
else:
Expand Down

0 comments on commit 9e555cd

Please sign in to comment.