@@ -46,6 +46,15 @@ pub struct ContainerDetails {
4646pub struct DockerManager {
4747 docker : Docker ,
4848 storage_path : String ,
49+ /// Controls whether to use host network mode for containers.
50+ ///
51+ /// Currently defaults to host mode (when false) to work around performance issues
52+ /// with Docker bridge networking on certain cloud providers. This is a trade-off
53+ /// between security isolation and performance.
54+ ///
55+ /// TODO: Investigate root cause of bridge network performance degradation and
56+ /// implement a more optimal solution that maintains security isolation.
57+ disable_host_network_mode : bool ,
4958}
5059
5160impl DockerManager {
@@ -128,7 +137,7 @@ impl DockerManager {
128137 }
129138
130139 /// Create a new DockerManager instance
131- pub fn new ( storage_path : String ) -> Result < Self , DockerError > {
140+ pub fn new ( storage_path : String , disable_host_network_mode : bool ) -> Result < Self , DockerError > {
132141 let docker = match Docker :: connect_with_unix_defaults ( ) {
133142 Ok ( docker) => docker,
134143 Err ( e) => {
@@ -159,6 +168,7 @@ impl DockerManager {
159168 Ok ( Self {
160169 docker,
161170 storage_path,
171+ disable_host_network_mode,
162172 } )
163173 }
164174
@@ -385,6 +395,12 @@ impl DockerManager {
385395 Some ( binds)
386396 } ;
387397
398+ let network_mode = if self . disable_host_network_mode {
399+ "bridge" . to_string ( )
400+ } else {
401+ "host" . to_string ( )
402+ } ;
403+
388404 let host_config = if gpu. is_some ( ) {
389405 let gpu = gpu. unwrap ( ) ;
390406 let device_ids = match & gpu. indices {
@@ -399,6 +415,7 @@ impl DockerManager {
399415 } ;
400416
401417 Some ( HostConfig {
418+ network_mode : Some ( network_mode) ,
402419 extra_hosts : Some ( vec ! [ "host.docker.internal:host-gateway" . into( ) ] ) ,
403420 device_requests : Some ( vec ! [ DeviceRequest {
404421 driver: Some ( "nvidia" . into( ) ) ,
@@ -417,6 +434,7 @@ impl DockerManager {
417434 } )
418435 } else {
419436 Some ( HostConfig {
437+ network_mode : Some ( network_mode) ,
420438 extra_hosts : Some ( vec ! [ "host.docker.internal:host-gateway" . into( ) ] ) ,
421439 binds : volume_binds,
422440 restart_policy : Some ( bollard:: models:: RestartPolicy {
0 commit comments