GitLab runner pulls image for every job

Viewed 12376

I have a GitLab runner using docker as the executor. My problem is, it pulls the image I have defined for every job, which takes more time to finish the pipeline

enter image description here

How can I cache the image and add a pull policy for the job or the runner ? Anyone please?

3 Answers

The pull policy by default for a docker executor is "Always". You can use "if-not-present" pull policy to make sure it is only pulled when it is not available locally.

Read the documentation for option here and how the policies work here

Check if the latest GitLab 13.8 (January 2021) can help.

Configure multiple image pull policies for Docker executor

When your CI jobs are retrieving a container image from a container registry, a lost network connection can result in hours of lost development time and can negatively impact time-sensitive product deployments.

To address this resiliency problem, the GitLab Runner Docker executor now supports the use of multiple values for the pull_policy configuration, which is defined in the GitLab Runner config.toml file.

You can use these values, or stacked image pull policies, to configure combinations of pull policies and mitigate the impact caused by lost connectivity.

For example, if you configure pull_policy =[always, if-not-present], the pull policy will always pull the image.
However, if the target container registry is not available, the GitLab Runner Docker executor will fall back and use the if-not-present policy, which means a local copy of the image will be used for that pipeline job.

https://about.gitlab.com/images/13_8/runner-docker-pull-policy.png -- Configure multiple image pull policies for Docker executor

See Documentation and Issue.


GitLab 15.2 (July 2022) adds:

Set the image pull policy in pipeline configuration

You can select different pull policies for how a GitLab Runner downloads Docker images in CI/CD jobs.

  • always (the default behavior) ensures the image is always downloaded,
  • if-not-present downloads an image only when a local version does not exist, and
  • never only uses the local version (never download an image).

Previously, you could define the pull policy only at the runner level. In this release we’ve added the ability to define the pull policy at the pipeline level. Use pull_policy in your .gitlab-ci.yml to define different pull policies at the job or pipeline level. This feature is not supported by shared runners.

https://about.gitlab.com/images/15_2/pull_policy.png -- Set the image pull policy in pipeline configuration

See Documentation and Issue.

Related