Use ghcr in Dockerfile in GHA

2.4k Views Asked by At

I would like to use ghcr as cache to store docker image with part which almost do not change in my project (Ubuntu, miniconda and bunch of Python packages) and then use this image in Dockerfile which adds volumes and code of the project to it. Dockerfile is run by Github Actions. How could I reference to ghcr stored image in From statement of Dockerfile?

2

There are 2 best solutions below

0
On BEST ANSWER

How could I reference to ghcr stored image in From statement of Dockerfile?

Image references have the registry in front of them, and when not included, will default to Docker Hub. So for a registry like ghcr you want:

FROM ghcr.io/path/to/image:tag
2
On

@BMitch's solution worked for me for one public package but not another. Weird..

When I ran docker build I got this:

failed to solve with frontend dockerfile.v0: failed to create LLB definition: failed to authorize: rpc error: code = Unknown desc = failed to fetch anonymous token: unexpected status: 403 Forbidden

A common cause of this error is a typo in the name of the dockerfile.

But I had no typo.

Running this once solved it:

docker pull <ghcr.io/path/to/image:tag>

Note:

  • It may or may not have been related, but there was a some sort of bug in GitHub tokens, so I ran this to logout of GHCR with docker.