---
title: Use GitHub Container Registry images
description: >-
  Push an image to GitHub Container Registry, then run it as a job or a
  deployment with a read-only registry credential stored as a teamspace secret.
canonical: 'https://lightning.ai/docs/platform/build/container-images/github-containers'
---
# Use GitHub Container Registry images {#use-github-container-registry-images}

To use a private image from [GitHub Container Registry](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-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 {#push-a-container}

1. Open your <a href="https://github.com/settings/tokens" target="_blank" rel="noopener">personal access tokens (classic)</a> 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.

   ```bash
   # 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 {#run-the-container-in-a-job-or-a-deployment}

### Create a read-only token {#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 <a href="https://github.com/settings/tokens" target="_blank" rel="noopener">personal access tokens (classic)</a> 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.

   ```bash
   # 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 {#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 {#run-it-as-a-job}

Pass the secret's name as `image_credentials`:

```python
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](/docs/platform/inference/batch-jobs/submit-jobs.md) for all the job options.

### Run it as a deployment {#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 {#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 {#see-also}

- [Managed secrets](/docs/platform/build/ai-studio/managed-secrets.md), for how teamspace secrets are stored.
- [Use container images](/docs/platform/build/container-images.md), for the other registries.

---

**Navigation**

- Parent: [Use container images](/docs/platform/build/container-images.md)
