33
33
)
34
34
35
35
36
+ CONTAINER_NETWORK = "CONTAINER_NETWORK"
37
+
38
+
36
39
def get_service_pack_prefix () -> Dict :
37
40
curr_dir = os .path .dirname (os .path .abspath (__file__ ))
38
41
service_config_file = os .path .join (curr_dir , "conda" , "config.yaml" )
@@ -175,11 +178,13 @@ def build_image(
175
178
command += ["--build-arg" , f"http_proxy={ os .environ ['http_proxy' ]} " ]
176
179
if os .environ .get ("https_proxy" ):
177
180
command += ["--build-arg" , f"https_proxy={ os .environ ['https_proxy' ]} " ]
181
+ if os .environ .get (CONTAINER_NETWORK ):
182
+ command += ["--network" , os .environ [CONTAINER_NETWORK ]]
178
183
command += [os .path .abspath (curr_dir )]
179
- logger .info (f "Build image with command { command } " )
184
+ logger .info ("Build image with command %s" , command )
180
185
proc = run_command (command )
181
186
if proc .returncode != 0 :
182
- raise RuntimeError (f "Docker build failed." )
187
+ raise RuntimeError ("Docker build failed." )
183
188
184
189
185
190
def _get_image_name_dockerfile_target (type : str , gpu : bool ) -> str :
@@ -343,6 +348,9 @@ def run_container(
343
348
logger .warning (f"Image { image } not found. Try pulling it now...." )
344
349
run_command (["docker" , "pull" , f"{ image } " ], None )
345
350
try :
351
+ kwargs = {}
352
+ if CONTAINER_NETWORK in os .environ :
353
+ kwargs ["network_mode" ] = os .environ [CONTAINER_NETWORK ]
346
354
container = client .containers .run (
347
355
image = image ,
348
356
volumes = bind_volumes ,
@@ -351,6 +359,7 @@ def run_container(
351
359
detach = True ,
352
360
entrypoint = entrypoint ,
353
361
user = 0 ,
362
+ ** kwargs
354
363
# auto_remove=True,
355
364
)
356
365
logger .info ("Container ID: %s" , container .id )
0 commit comments