@@ -7,11 +7,11 @@ import (
77 "errors"
88 "fmt"
99 "os"
10- "regexp"
1110 "strconv"
1211 "strings"
1312 "time"
1413
14+ "github.com/containerd/errdefs"
1515 "github.com/docker/docker/api/types/container"
1616 "github.com/docker/docker/api/types/filters"
1717 "github.com/docker/docker/api/types/mount"
@@ -25,11 +25,6 @@ import (
2525// controllerContainerName is the name to use for the controller container.
2626const controllerContainerName = "docker-model-runner"
2727
28- // concurrentInstallMatcher matches error message that indicate a concurrent
29- // standalone model runner installation is taking place. It extracts the ID of
30- // the conflicting container in a capture group.
31- var concurrentInstallMatcher = regexp .MustCompile (`is already in use by container "([a-z0-9]+)"` )
32-
3328// copyDockerConfigToContainer copies the Docker config file from the host to the container
3429// and sets up proper ownership and permissions for the modelrunner user.
3530// It does nothing for Desktop and Cloud engine kinds.
@@ -197,7 +192,7 @@ func waitForContainerToStart(ctx context.Context, dockerClient client.ContainerA
197192 // until the polling time out - unfortunately we can't make the 404
198193 // acceptance window any smaller than that because the CUDA-based
199194 // containers are large and can take time to create).
200- if ! strings . Contains (err . Error (), "No such container" ) {
195+ if ! errdefs . IsNotFound (err ) {
201196 return fmt .Errorf ("unable to inspect container (%s): %w" , containerID [:12 ], err )
202197 }
203198 } else {
@@ -284,8 +279,8 @@ func CreateControllerContainer(ctx context.Context, dockerClient *client.Client,
284279 // container first and then wait for its container to be ready.
285280 resp , err := dockerClient .ContainerCreate (ctx , config , hostConfig , nil , nil , controllerContainerName )
286281 if err != nil {
287- if match := concurrentInstallMatcher . FindStringSubmatch (err . Error ()); match != nil {
288- if err := waitForContainerToStart (ctx , dockerClient , match [ 1 ] ); err != nil {
282+ if errdefs . IsConflict (err ) {
283+ if err := waitForContainerToStart (ctx , dockerClient , controllerContainerName ); err != nil {
289284 return fmt .Errorf ("failed waiting for concurrent installation: %w" , err )
290285 }
291286 return nil
0 commit comments