Skip to content

Commit 5dc4847

Browse files
committed
fix(Docker): ensure fresh GPU detection when Ollama ctr updated
1 parent b0b8f07 commit 5dc4847

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

admin/app/services/docker_service.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,45 @@ export class DockerService {
853853
this._broadcast(serviceName, 'update-creating', `Creating updated container...`)
854854

855855
const hostConfig = inspectData.HostConfig || {}
856+
857+
// Re-run GPU detection for Ollama so updates always reflect the current GPU environment.
858+
// This handles cases where the NVIDIA Container Toolkit was installed after the initial
859+
// Ollama setup, and ensures DeviceRequests are always built fresh rather than relying on
860+
// round-tripping the Docker inspect format back into the create API.
861+
let updatedDeviceRequests: any[] | undefined = undefined
862+
if (serviceName === SERVICE_NAMES.OLLAMA) {
863+
const gpuResult = await this._detectGPUType()
864+
865+
if (gpuResult.type === 'nvidia') {
866+
this._broadcast(
867+
serviceName,
868+
'update-gpu-config',
869+
`NVIDIA container runtime detected. Configuring updated container with GPU support...`
870+
)
871+
updatedDeviceRequests = [
872+
{
873+
Driver: 'nvidia',
874+
Count: -1,
875+
Capabilities: [['gpu']],
876+
},
877+
]
878+
} else if (gpuResult.type === 'amd') {
879+
this._broadcast(
880+
serviceName,
881+
'update-gpu-config',
882+
`AMD GPU detected. ROCm GPU acceleration is not yet supported — using CPU-only configuration.`
883+
)
884+
} else if (gpuResult.toolkitMissing) {
885+
this._broadcast(
886+
serviceName,
887+
'update-gpu-config',
888+
`NVIDIA GPU detected but NVIDIA Container Toolkit is not installed. Using CPU-only configuration. Install the toolkit and reinstall AI Assistant for GPU acceleration: https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html`
889+
)
890+
} else {
891+
this._broadcast(serviceName, 'update-gpu-config', `No GPU detected. Using CPU-only configuration.`)
892+
}
893+
}
894+
856895
const newContainerConfig: any = {
857896
Image: newImage,
858897
name: serviceName,
@@ -865,7 +904,7 @@ export class DockerService {
865904
Binds: hostConfig.Binds || undefined,
866905
PortBindings: hostConfig.PortBindings || undefined,
867906
RestartPolicy: hostConfig.RestartPolicy || undefined,
868-
DeviceRequests: hostConfig.DeviceRequests || undefined,
907+
DeviceRequests: serviceName === SERVICE_NAMES.OLLAMA ? updatedDeviceRequests : (hostConfig.DeviceRequests || undefined),
869908
Devices: hostConfig.Devices || undefined,
870909
},
871910
NetworkingConfig: inspectData.NetworkSettings?.Networks

0 commit comments

Comments
 (0)