Skip to content

Commit

Permalink
docker: handle image inspect and network destroy.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasell committed Jul 7, 2022
1 parent 402e594 commit e3a60b4
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions drivers/docker/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,28 @@ func (d *Driver) DestroyNetwork(allocID string, spec *drivers.NetworkIsolationSp
return fmt.Errorf("failed to connect to docker daemon: %s", err)
}

return client.RemoveContainer(docker.RemoveContainerOptions{
if err := client.RemoveContainer(docker.RemoveContainerOptions{
Force: true,
ID: spec.Labels[dockerNetSpecLabelKey],
})
}); err != nil {
return err
}

if d.config.GC.Image {

// The Docker image ID is needed in order to correctly update the image
// reference count. Any error finding this, however, should not result
// in an error shutting down the allocrunner.
dockerImage, err := client.InspectImage(d.config.InfraImage)
if err != nil {
d.logger.Warn("InspectImage failed for infra_image container destroy",
"image", d.config.InfraImage, "error", err)
return nil
}
d.coordinator.RemoveImage(dockerImage.ID, allocID)
}

return nil
}

// createSandboxContainerConfig creates a docker container configuration which
Expand Down Expand Up @@ -124,8 +142,8 @@ func (d *Driver) pullInfraImage(allocID string) error {
if tag != "latest" {
dockerImage, err := client.InspectImage(d.config.InfraImage)
if err != nil {
d.logger.Debug("InspectImage failed for infra_image container pull", "image", d.config.InfraImage, "error", err)
return err
d.logger.Debug("InspectImage failed for infra_image container pull",
"image", d.config.InfraImage, "error", err)
} else if dockerImage != nil {
// Image exists, so no pull is attempted; just increment its reference count
d.coordinator.IncrementImageReference(dockerImage.ID, d.config.InfraImage, allocID)
Expand Down

0 comments on commit e3a60b4

Please sign in to comment.