@@ -91,7 +91,8 @@ func copyDockerConfigToContainer(ctx context.Context, dockerClient *client.Clien
9191
9292func execInContainer (ctx context.Context , dockerClient * client.Client , containerID , cmd string ) error {
9393 execConfig := container.ExecOptions {
94- Cmd : []string {"sh" , "-c" , cmd },
94+ Cmd : []string {"sh" , "-c" , cmd },
95+ User : "root" ,
9596 }
9697 execResp , err := dockerClient .ContainerExecCreate (ctx , containerID , execConfig )
9798 if err != nil {
@@ -267,8 +268,12 @@ func tryGetBindAscendMounts(printer StatusPrinter, debug bool) []mount.Mount {
267268 return newMounts
268269}
269270
271+ // proxyCertContainerPath is the path where the proxy certificate will be mounted in the container.
272+ // This location is used by update-ca-certificates to add the cert to the system trust store.
273+ const proxyCertContainerPath = "/usr/local/share/ca-certificates/proxy-ca.crt"
274+
270275// CreateControllerContainer creates and starts a controller container.
271- func CreateControllerContainer (ctx context.Context , dockerClient * client.Client , port uint16 , host string , environment string , doNotTrack bool , gpu gpupkg.GPUSupport , backend string , modelStorageVolume string , printer StatusPrinter , engineKind types.ModelRunnerEngineKind , debug bool , vllmOnWSL bool ) error {
276+ func CreateControllerContainer (ctx context.Context , dockerClient * client.Client , port uint16 , host string , environment string , doNotTrack bool , gpu gpupkg.GPUSupport , backend string , modelStorageVolume string , printer StatusPrinter , engineKind types.ModelRunnerEngineKind , debug bool , vllmOnWSL bool , proxyCert string ) error {
272277 imageName := controllerImageName (gpu , backend )
273278
274279 // Set up the container configuration.
@@ -288,6 +293,7 @@ func CreateControllerContainer(ctx context.Context, dockerClient *client.Client,
288293 env = append (env , proxyVar + "=" + value )
289294 }
290295 }
296+
291297 config := & container.Config {
292298 Image : imageName ,
293299 Env : env ,
@@ -316,6 +322,15 @@ func CreateControllerContainer(ctx context.Context, dockerClient *client.Client,
316322 hostConfig .Mounts = append (hostConfig .Mounts , ascendMounts ... )
317323 }
318324
325+ if proxyCert != "" {
326+ hostConfig .Mounts = append (hostConfig .Mounts , mount.Mount {
327+ Type : mount .TypeBind ,
328+ Source : proxyCert ,
329+ Target : proxyCertContainerPath ,
330+ ReadOnly : true ,
331+ })
332+ }
333+
319334 portBindings := []nat.PortBinding {{HostIP : host , HostPort : portStr }}
320335 if os .Getenv ("_MODEL_RUNNER_TREAT_DESKTOP_AS_MOBY" ) != "1" {
321336 // Don't bind the bridge gateway IP if we're treating Docker Desktop as Moby.
@@ -437,6 +452,23 @@ func CreateControllerContainer(ctx context.Context, dockerClient *client.Client,
437452 printer .Printf ("Warning: failed to copy Docker config: %v\n " , err )
438453 }
439454 }
455+
456+ // Add proxy certificate to the system CA bundle
457+ if created && proxyCert != "" {
458+ printer .Printf ("Adding proxy certificate to CA bundle...\n " )
459+ // Append the proxy cert to the system CA bundle
460+ appendCmd := "cat " + proxyCertContainerPath + " >> /etc/ssl/certs/ca-certificates.crt"
461+ if err := execInContainer (ctx , dockerClient , resp .ID , appendCmd ); err != nil {
462+ printer .Printf ("Warning: failed to add proxy certificate to CA bundle: %v\n " , err )
463+ } else {
464+ // Restart the container so the model-runner process picks up the new CA bundle
465+ printer .Printf ("Restarting container to apply CA certificate...\n " )
466+ if err := dockerClient .ContainerRestart (ctx , resp .ID , container.StopOptions {}); err != nil {
467+ printer .Printf ("Warning: failed to restart container after adding CA certificate: %v\n " , err )
468+ }
469+ }
470+ }
471+
440472 return nil
441473}
442474
0 commit comments