How to pull and run a docker image from a registry?

I have a gitlab registry with some docker images that I want to run using prefect 2.0

When I try to run the following, I get an error


reg = docker.DockerRegistry(username=user, password=pw, registry_url="gitlab.some.container.com:5004/tool-registry")
b = docker.DockerContainer(image_registry = reg, command=["run file.sh"],  image=image_tag)
print(b.preview())
b.run()

I get a 404 Client Error: Not Found for url: http+docker://localhost/v1.41/images/create?tag=latest&fromImage=0d191eb865749afb42ebdfd700a2a975c1f20b95. The thing is this url seems very wrong to me… I would have though it was something like gitlab.company.com.au:5004/tool-name:0d191eb865749afb42ebdfd700a2a975c1f20b95

This is the traceback.

12:07:43.188 | INFO    | prefect.infrastructure.docker-container - Pulling image '0d191eb865749afb42ebdfd700a2a975c1f20b95'...
Traceback (most recent call last):
  File "/home/usr/anaconda3/envs/sandbox/lib/python3.10/site-packages/docker/api/client.py", line 268, in _raise_for_status
    response.raise_for_status()
  File "/home/usr/anaconda3/envs/sandbox/lib/python3.10/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: http+docker://localhost/v1.41/images/create?tag=latest&fromImage=0d191eb865749afb42ebdfd700a2a975c1f20b95

Any help would be appreciated

1 Like

Nevermind, problem was the image had to be the full url, not the image_tag

So working code was to have

image_tag = "gitlab.company.com.au:5004/tool-name:0d191eb865749afb42ebdfd700a2a975c1f20b95"
1 Like

thanks so much for sharing your solution :raised_hands: great to see you figure that out so quickly

1 Like