Use DockerHub images

To use a private DockerHub image in Lightning AI, give it a read-only token.

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.

    # 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

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

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

  1. Copy the generated token:

Once generated, copy the personal access token

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.
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 for all the job options.

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

Was this page helpful?

What went wrong?

↑↓ Navigate↵ Open⌘↵ New tabesc Close