@@ -265,24 +265,31 @@ func CreateControllerContainer(ctx context.Context, dockerClient *client.Client,
265265 }
266266
267267 // Create the container. If we detect that a concurrent installation is in
268- // progress, then we wait for whichever install process creates the
269- // container first and then wait for its container to be ready.
268+ // progress (as indicated by a conflicting container name (which should have
269+ // been detected just before installation)), then we'll allow the error to
270+ // pass silently and simply work in conjunction with any concurrent
271+ // installers to start the container.
270272 resp , err := dockerClient .ContainerCreate (ctx , config , hostConfig , nil , nil , controllerContainerName )
271- if ! errdefs .IsConflict (err ) {
273+ if err != nil && ! errdefs .IsConflict (err ) {
272274 return fmt .Errorf ("failed to create container %s: %w" , controllerContainerName , err )
273275 }
276+ created := err == nil
274277
275278 // Start the container.
276279 printer .Printf ("Starting model runner container %s...\n " , controllerContainerName )
277280 if err := waitForContainerToStart (ctx , dockerClient , controllerContainerName ); err != nil {
278- _ = dockerClient .ContainerRemove (ctx , resp .ID , container.RemoveOptions {Force : true })
281+ if created {
282+ _ = dockerClient .ContainerRemove (ctx , resp .ID , container.RemoveOptions {Force : true })
283+ }
279284 return fmt .Errorf ("failed to start container %s: %w" , controllerContainerName , err )
280285 }
281286
282- // Copy Docker config file if it exists
283- if err := copyDockerConfigToContainer (ctx , dockerClient , resp .ID , engineKind ); err != nil {
284- // Log warning but continue - don't fail container creation
285- printer .Printf ("Warning: failed to copy Docker config: %v\n " , err )
287+ // Copy Docker config file if it exists and we're the container creator.
288+ if created {
289+ if err := copyDockerConfigToContainer (ctx , dockerClient , resp .ID , engineKind ); err != nil {
290+ // Log warning but continue - don't fail container creation
291+ printer .Printf ("Warning: failed to copy Docker config: %v\n " , err )
292+ }
286293 }
287294 return nil
288295}
0 commit comments