20
20
)
21
21
22
22
LOCALNET_IMAGE_NAME = "ghcr.io/opentensor/subtensor-localnet:devnet-ready"
23
+ CONTAINER_NAME_PREFIX = "test_local_chain_"
23
24
24
25
25
26
def wait_for_node_start (process , timestamp = None ):
@@ -163,7 +164,25 @@ def try_start_docker():
163
164
print ("Docker wasn't run. Manual start may be required." )
164
165
return False
165
166
166
- container_name = f"test_local_chain_{ str (time .time ()).replace ('.' , '_' )} "
167
+ def stop_existing_test_containers ():
168
+ """Stop running Docker containers with names starting with 'test_local_chain_'."""
169
+ try :
170
+ existing_container_result = subprocess .run (
171
+ ["docker" , "ps" , "--filter" , f"name={ CONTAINER_NAME_PREFIX } " , "--format" , "{{.ID}}" ],
172
+ stdout = subprocess .PIPE ,
173
+ stderr = subprocess .PIPE ,
174
+ text = True ,
175
+ check = True
176
+ )
177
+ container_ids = existing_container_result .stdout .strip ().splitlines ()
178
+ for cid in container_ids :
179
+ if cid :
180
+ print (f"Stopping existing container: { cid } " )
181
+ subprocess .run (["docker" , "stop" , cid ], check = True )
182
+ except subprocess .CalledProcessError as e :
183
+ print (f"Failed to stop existing containers: { e } " )
184
+
185
+ container_name = f"{ CONTAINER_NAME_PREFIX } { str (time .time ()).replace ('.' , '_' )} "
167
186
168
187
# Command to start container
169
188
cmds = [
@@ -182,6 +201,8 @@ def try_start_docker():
182
201
183
202
try_start_docker ()
184
203
204
+ stop_existing_test_containers ()
205
+
185
206
# Start container
186
207
with subprocess .Popen (
187
208
cmds ,
0 commit comments