Skip updating containers where no local image info can be retrieved (#612)

* Revert "Image of running container no longer needed locally (#571)"

This reverts commit 6da66fb312.

* Update client.go

* fix: skip updating when no image info can be retrieved

This will allow watchtower to continue even though the image info for a
container cannot be retrieved. If this happens one warning will be emitted
and the container will be skipped, unless NoRestart or OnlyMonitor is supplied
This commit is contained in:
nils måsén 2020-08-18 20:55:35 +02:00 committed by GitHub
parent cde438996a
commit 5efb249a86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 10 deletions

View file

@ -119,8 +119,12 @@ func (client dockerClient) GetContainer(containerID string) (Container, error) {
return Container{}, err
}
container := Container{containerInfo: &containerInfo}
return container, nil
imageInfo, _, err := client.api.ImageInspectWithRaw(bg, containerInfo.Image)
if err != nil {
log.Warnf("Failed to retrieve container image info: %v", err)
}
return Container{containerInfo: &containerInfo, imageInfo: &imageInfo}, nil
}
func (client dockerClient) StopContainer(c Container, timeout time.Duration) error {

View file

@ -221,3 +221,8 @@ func (c Container) hostConfig() *dockercontainer.HostConfig {
return hostConfig
}
// HasImageInfo returns whether image information could be retrieved for the container
func (c Container) HasImageInfo() bool {
return c.imageInfo != nil
}