Use GitHub Container Registry images
To use a private image from GitHub Container Registry (ghcr.io), store a GitHub token as a registry credential in your teamspace. For a public image, run the job without image_credentials, or deploy without selecting Registry credentials.
Push a container
Open your personal access tokens (classic) page on GitHub. GitHub Packages doesn't support fine-grained tokens.
Click Generate new token (classic).
Select the
write:packagesscope, then generate the token and copy it.Log in, and push an image to your GitHub account.
# login echo "$GITHUB_TOKEN" | docker login ghcr.io -u <github-username> --password-stdin # pull test image (or use your own) docker pull nginx:latest # tag docker tag nginx:latest ghcr.io/<owner>/nginx-test:latest # push docker push ghcr.io/<owner>/nginx-test:latest
Run the container in a job or a deployment
Create a read-only token
Lightning AI only needs to pull the image, so the token only needs the read:packages scope.
Open your personal access tokens (classic) page on GitHub. GitHub Packages doesn't support fine-grained tokens.
Click Generate new token (classic).
Select the
read:packagesscope, then generate the token and copy it.Pull the image with the read-only token to check that it works.
# login echo "$GITHUB_READ_TOKEN" | docker login ghcr.io -u <github-username> --password-stdin # pull docker pull ghcr.io/<owner>/nginx-test:latest
Create the registry credential
- Open your teamspace's settings and click Secrets.
- Click New Secret, then select the Credential tab.
- Enter a Name, for example
ghcr_pull. - In Username, enter your GitHub username. In Password, paste the
read:packagestoken. - Click Create.
Run it as a job
Pass the secret's name as image_credentials:
from lightning_sdk import Job, Machine, Teamspace
teamspace = Teamspace(name="my-teamspace", org="my-org")
submitted_job = Job.run(
name="my-job",
command="echo hello",
image="ghcr.io/<owner>/nginx-test:latest",
machine=Machine.CPU,
teamspace=teamspace,
image_credentials="ghcr_pull",
)With the CLI, use --image-credentials=ghcr_pull. See Submit jobs for all the job options.
Run it as a deployment
In the deployment dialog, enter ghcr.io/<owner>/nginx-test:latest as the image, expand Registry credentials, select your secret, and click Deploy.
Troubleshooting
Deployment fails with "Container: Image not publicly available." The image is private and no credential is set. Add one under Registry credentials.
Job or deployment fails with failed to get secret '<name>' value.
No secret with that name exists. It was deleted, or the name doesn't match. Create the credential again with the same name.
Job fails with failed to decode secret '<name>' value.
The secret wasn't created from the Credential tab. Delete it and create it again.
See also
- Managed secrets, for how teamspace secrets are stored.
- Use container images, for the other registries.
Was this page helpful?
Thanks for the feedback.