func (imageState *ImageState) RemoveContainerReference(container *api.Container) error { // Get the image state write lock for updating container reference imageState.updateLock.Lock() defer imageState.updateLock.Unlock() for i, _ := range imageState.Containers { if imageState.Containers[i].Name == container.Name { // Container reference found; hence remove it seelog.Infof("Removing Container Reference: %v from Image State- %v", container.Name, imageState.Image.ImageID) imageState.Containers = append(imageState.Containers[:i], imageState.Containers[i+1:]...) // Update the last used time for the image imageState.LastUsedAt = time.Now() return nil } } return fmt.Errorf("Container reference is not found in the image state container: %s", container.String()) }