Skip to content

Commit f43c6a4

Browse files
authored
fix(main): disconnect networks early on "stop" (#12)
This reduces the chance of having dangling networks left. This can happen if all services are removed from a network and the network is automatically removed as is the case with e.g. "docker compose down". If Traefik does not leave a network quickly enough, the network is left unchanged because it is still "in use".
1 parent 2799f03 commit f43c6a4

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

main.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def monitor_events():
188188

189189
# Define the Docker events to track for managing Traefik connections
190190
tracked_events = {
191-
"container": ["start", "die"],
191+
"container": ["start", "stop", "die"],
192192
}
193193

194194
# Listen to Docker events in real-time
@@ -234,9 +234,15 @@ def monitor_events():
234234
app_logger.info(f"Container {container.name} is being created. Attempting to connect Traefik to relevant networks.")
235235
connect_traefik_to_network(container)
236236

237+
elif event["Action"] == "stop":
238+
app_logger.info(
239+
f"Container {container.name} is being stopped. Attempting to disconnect Traefik from relevant networks."
240+
)
241+
disconnect_traefik_from_network(container)
242+
237243
elif event["Action"] == "die":
238244
app_logger.info(
239-
f"Container {container.name} is being killed. Attempting to disconnect Traefik to relevant networks."
245+
f"Container {container.name} is being killed. Attempting to disconnect Traefik from relevant networks."
240246
)
241247
disconnect_traefik_from_network(container)
242248
del container_cache[event["id"]]

0 commit comments

Comments
 (0)