Skip to content

Commit

Permalink
[shim] Before creating a new container, stop and remove the previous one
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Mezentsev committed Mar 22, 2024
1 parent c768007 commit 2d4a797
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions runner/internal/shim/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,19 @@ func pullImage(ctx context.Context, client docker.APIClient, taskParams DockerIm
}

func createContainer(ctx context.Context, client docker.APIClient, dockerParams DockerParameters, taskParams DockerImageConfig) (string, error) {
timeout := int(0)
stopOptions := container.StopOptions{Timeout: &timeout}
err := client.ContainerStop(ctx, taskParams.ContainerName, stopOptions)
if err != nil {
log.Printf("Unable to stop the container: %s", err)
}

removeOptions := types.ContainerRemoveOptions{Force: true}
err = client.ContainerRemove(ctx, taskParams.ContainerName, removeOptions)
if err != nil {
log.Printf("Unable to remove the container: %s", err)
}

gpuRequest, err := requestGpuIfAvailable(ctx, client)
if err != nil {
return "", tracerr.Wrap(err)
Expand Down

0 comments on commit 2d4a797

Please sign in to comment.