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

  1. Open your personal access tokens (classic) page on GitHub. GitHub Packages doesn't support fine-grained tokens.

  2. Click Generate new token (classic).

  3. Select the write:packages scope, then generate the token and copy it.

  4. 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.

  1. Open your personal access tokens (classic) page on GitHub. GitHub Packages doesn't support fine-grained tokens.

  2. Click Generate new token (classic).

  3. Select the read:packages scope, then generate the token and copy it.

  4. 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

  1. Open your teamspace's settings and click Secrets.
  2. Click New Secret, then select the Credential tab.
  3. Enter a Name, for example ghcr_pull.
  4. In Username, enter your GitHub username. In Password, paste the read:packages token.
  5. 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

Was this page helpful?

What went wrong?

↑↓ Navigate↵ Open⌘↵ New tabesc Close