---
title: Use DockerHub images
description: >-
  To use a private DockerHub image in Lightning AI, give it a read-only token.
  Use this demo to get an image into DockerHub if you don't have one yet....
canonical: 'https://lightning.ai/docs/platform/build/container-images/dockerhub'
---
# Use DockerHub images {#use-dockerhub-images}

To use a private [DockerHub](https://hub.docker.com/) image in Lightning AI, give it a read-only token.

## Push a container {#push-a-container}

Use this demo to get an image into DockerHub if you don't have one yet. Pushing needs a token with **Read & Write** permissions.

1. Go to your DockerHub personal access tokens page: https://app.docker.com/settings/personal-access-tokens
2. Generate a new token with "Read & Write" permissions and copy it.
3. Log in, push an `nginx` image to your account, and pull it back. `docker login` asks for the token as the password.

   ```bash
   # login
   docker login -u <dockerhub-username>
   # pull test image (or use your own)
   docker pull nginx:latest
   # tag
   docker tag nginx:latest <dockerhub-username>/nginx-test:latest
   # push
   docker push <dockerhub-username>/nginx-test:latest
   # pull
   docker pull <dockerhub-username>/nginx-test:latest
   ```

4. A repository created by a push is public by default. Make it private in DockerHub, so the run demo tests the credential.

## Run the container in a job or a deployment {#run-the-container-in-a-job-or-a-deployment}

Lightning AI only needs to pull the image, so the token only needs read-only permissions.

### Create a read-only token {#create-a-read-only-token}

1. Go to your DockerHub personal access tokens page: https://app.docker.com/settings/personal-access-tokens

2. Generate a new token with "Read-only" permissions:

![Generating a new token](https://lightning.ai/v1/media/litpages/01j4mf2fcgrg8sfhq339x3t7ye/1c870eca-fe72-4283-9d4a-32c23148df9b.png)

3. Copy the generated token:

![Once generated, copy the personal access token](https://lightning.ai/v1/media/litpages/01j4mf2fcgrg8sfhq339x3t7ye/e384a734-6007-495a-96ef-1451e531e94f.png)

### Run it as a job {#run-it-as-a-job}

Create the DockerHub credential as a teamspace secret, then pass its name as `image_credentials`:

1. Open your teamspace's settings and click **Secrets**.
2. Click **New Secret**, then select the **Credential** tab.
3. Enter a **Name**, for example `dockerhub`.
4. In **Username**, enter your DockerHub username. In **Password**, paste the read-only token.
5. Click **Create**.

```python
from lightning_sdk import Job, Machine, Teamspace

teamspace = Teamspace(name="my-teamspace", user="my-user")

submitted_job = Job.run(
    name="my-job",
    command="cat /etc/os-release",
    image="<dockerhub-username>/nginx-test:latest",
    machine=Machine.CPU,
    teamspace=teamspace,
    image_credentials="dockerhub",
)
```

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}

When starting a deployment, enter `<dockerhub-username>/nginx-test:latest` as the image. Click on the registry credentials and specify the DockerHub username and the generated token as your password. Then click "Deploy".

![specify registry credentials](https://lightning.ai/v1/media/litpages/01j4mf2fcgrg8sfhq339x3t7ye/de27d906-319b-4a4d-81d7-ff8e8db9e115.png)

---

**Navigation**

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