diff --git a/container.go b/container.go index cc19399a9e..f17ec683e9 100644 --- a/container.go +++ b/container.go @@ -65,24 +65,25 @@ type FromDockerfile struct { // ContainerRequest represents the parameters used to get a running container type ContainerRequest struct { FromDockerfile - Image string - Env map[string]string - ExposedPorts []string // allow specifying protocol info - Cmd []string - Labels map[string]string - BindMounts map[string]string - VolumeMounts map[string]string - Tmpfs map[string]string - RegistryCred string - WaitingFor wait.Strategy - Name string // for specifying container name - Privileged bool // for starting privileged container - Networks []string // for specifying network names - NetworkAliases map[string][]string // for specifying network aliases - SkipReaper bool // indicates whether we skip setting up a reaper for this - ReaperImage string // alternative reaper image - AutoRemove bool // if set to true, the container will be removed from the host when stopped - NetworkMode container.NetworkMode + Image string + Env map[string]string + ExposedPorts []string // allow specifying protocol info + Cmd []string + Labels map[string]string + BindMounts map[string]string + VolumeMounts map[string]string + Tmpfs map[string]string + RegistryCred string + WaitingFor wait.Strategy + Name string // for specifying container name + Privileged bool // for starting privileged container + Networks []string // for specifying network names + NetworkAliases map[string][]string // for specifying network aliases + SkipReaper bool // indicates whether we skip setting up a reaper for this + ReaperImage string // alternative reaper image + AutoRemove bool // if set to true, the container will be removed from the host when stopped + NetworkMode container.NetworkMode + AlwaysPullImage bool // Always pull image } // ProviderType is an enum for the possible providers diff --git a/docker.go b/docker.go index 38256366d0..a383731c21 100644 --- a/docker.go +++ b/docker.go @@ -494,19 +494,28 @@ func (p *DockerProvider) CreateContainer(ctx context.Context, req ContainerReque } } else { tag = req.Image - _, _, err = p.client.ImageInspectWithRaw(ctx, tag) - if err != nil { - if client.IsErrNotFound(err) { - pullOpt := types.ImagePullOptions{} - if req.RegistryCred != "" { - pullOpt.RegistryAuth = req.RegistryCred - } + var shouldPullImage bool - if err := p.attemptToPullImage(ctx, tag, pullOpt); err != nil { + if req.AlwaysPullImage { + shouldPullImage = true // If requested always attempt to pull image + } else { + _, _, err = p.client.ImageInspectWithRaw(ctx, tag) + if err != nil { + if client.IsErrNotFound(err) { + shouldPullImage = true + } else { return nil, err } + } + } + + if shouldPullImage { + pullOpt := types.ImagePullOptions{} + if req.RegistryCred != "" { + pullOpt.RegistryAuth = req.RegistryCred + } - } else { + if err := p.attemptToPullImage(ctx, tag, pullOpt); err != nil { return nil, err } }