Solved gitlab-runner error: Failed to pull image with policy “always”: Error response from daemon
I met the issue while running gitlab pipleline.
I can docker pull
the image at the host and any other environments, but the pipeline running in docker container still failed. I could not fetch the image from remote Docker repository.
Here is the detail of the error message:
Using Docker executor with image <docker-repository-url>/python:3.9.15-slim ...
Pulling docker image <docker-repository-url>/python:3.9.15-slim ...
WARNING: Failed to pull image with policy "always": Error response from daemon: Head "https://<docker-repository-url>/python/manifests/3.9.15-slim": denied: You may not login yet (manager.go:237:0s)
ERROR: Job failed: failed to pull image "<docker-repository-url>/python:3.9.15-slim" with specified policies [always]: Error response from daemon: Head "https://<docker-repository-url>/python/manifests/3.9.15-slim": denied: You may not login yet (manager.go:237:0s)
The problem is because as Gitlab official explain:
If you use the
always
policy and the registry is not available, the job fails even if the desired image is cached locally.
Solve method
After reading this guidance at GitLab website, I changed config.toml
of gitlab-runner add a new line for pull_policy
as following:
[[runners]]
#....
[runners.docker]
pull_policy = ["if-not-present", "always"]
#...
It works.