---
title: Use custom Docker images with the legacy Python CLI
description: Use a custom Docker container image with AI Runtime (`air`) CLI workloads instead of managed Python dependencies.
canonical_url: https://docs.databricks.com/aws/en/machine-learning/ai-runtime/connecting/cli/legacy-cli/docker-images
---

# Use custom Docker images with the legacy Python CLI

> [!IMPORTANT]
>
> This documentation has been retired and might not be updated.
>
> The Python-based `air` CLI, installed with the `databricks-air` package, is now deprecated and is no longer actively maintained.
>
> Use the Databricks CLI for new workloads. See [Use the Databricks CLI with AI Runtime](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/connecting/cli/index.md).

> [!IMPORTANT]
>
> This feature is in [Beta](https://docs.databricks.com/aws/en/release-notes/release-types.md). To use it, a workspace admin must enable the **AI Runtime Beta Features** preview from the workspace [Previews page](https://docs.databricks.com/aws/en/admin/workspace-settings/manage-previews.md#workspace).

Docker Container Services (DCS) lets you bring your own Docker container image to `air` workloads. Use a custom image when you need:

* Specific system library versions.
* Complex dependencies that don't fit cleanly into `environment.dependencies`.
* An exact environment to reproduce research results.
* Standard images built by your organization's platform or security team.

## Prerequisites

* [Install the AI Runtime CLI](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/connecting/cli/legacy-cli/installation.md).
* A workspace admin has enabled the **AI Runtime Beta Features** preview. For instructions, see [ Manage workspace-level previews](https://docs.databricks.com/aws/en/admin/workspace-settings/manage-previews.md#workspace).
* For private images, a Docker Hub account with access to your image.

## Register an image

Before running a workload with a custom image, register it with `air register image`. Registration pulls and caches the image in the Databricks platform. Each user must register an image once per image tag. Re-register only when you push a new tag or rotate credentials. Registration takes 2–6 minutes and blocks until the image is ready.

### Public images

Register public images by providing the Docker image URL and your Databricks profile:

```shell
air register image docker.io/nvidia/cuda:12.9.0-devel-ubuntu24.04 -p my-databricks-profile
```

The short form image reference also works. For example, `library/ubuntu:latest`.

### Private Docker Hub images

To register a private Docker Hub image, generate a personal access token first. In your Docker Hub account settings, click **Personal access tokens** → **Generate new token**. Read-only access is sufficient.

Choose one of the following authentication methods:

#### Using docker login (recommended for interactive use)

Log in to Docker Hub at the terminal. You will be prompted for your Docker Hub username and personal access token:

```shell
docker login
```

This stores your credentials in `~/.docker/config.json`. Then register the image — `air` reads the credentials automatically:

```shell
air register image myorg/myrepo:mytag -p my-databricks-profile
```

#### Using interactive authentication

Authenticate and store credentials in a Databricks secret scope in one step:

```shell
air register image myorg/myrepo:mytag --interactive-authenticate -p my-databricks-profile
```

You will be prompted for your Docker Hub username and personal access token. Credentials are stored in your workspace secret scope for future registrations.

#### Using a pre-stored Databricks secret (recommended for CI/scripts)

Store credentials in a Databricks secret and reference it directly:

```shell
air register image myorg/myrepo:mytag --scope my-secret-scope --key my-docker-key -p my-databricks-profile
```

## Use a Docker image in a workload

Specify the Docker image in your workload YAML under `environment.docker_image.url`:

```yaml
experiment_name: my-dcs-training
environment:
  docker_image:
    url: myorg/myrepo:mytag
compute:
  num_accelerators: 1
  accelerator_type: GPU_1xA10
command: python /app/train.py
```

When bringing your own Docker image, `environment.dependencies` and `environment.version` are not supported. Specifying `environment.docker_image.url` with either field triggers an error. If you have additional dependencies, install the packages in the Dockerfile instead.

Submit the workload:

```shell
air run --file workload.yaml -p my-databricks-profile
```

## Environment variables injected into your container

AI Runtime injects the following environment variables into every container at runtime:

* `NUM_NODES` — total number of nodes.
* `LOCAL_WORLD_SIZE` — GPUs per node.
* `WORLD_SIZE` — total number of processes.
* `POD_RANK` — current node rank (0-indexed). Also injected as `NODE_RANK`.
* `MASTER_ADDR` — rank-0 coordination address (multi-node only).
* `MASTER_PORT` — rank-0 coordination port (multi-node only).

## Examples

### Single-node A10

```yaml
experiment_name: my-dcs-single-node
environment:
  docker_image:
    url: myorg/myrepo:mytag
compute:
  num_accelerators: 1
  accelerator_type: GPU_1xA10
command: python3 /app/train.py
```

### Multi-node H100 with RDMA

For multi-node H100 jobs that need full network bandwidth on AWS p5 instances, base your image on one of the [Databricks base images](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/connecting/cli/legacy-cli/docker-images.md#databricks-base-images) with NCCL and EFA preconfigured:

```yaml
experiment_name: my-dcs-distributed
environment:
  docker_image:
    url: myorg/myrepo:mytag
compute:
  num_accelerators: 16 # 2 nodes × 8 H100
  accelerator_type: GPU_8xH100
command: |-
  torchrun \
    --nnodes="${NUM_NODES}" \
    --nproc_per_node="${LOCAL_WORLD_SIZE}" \
    --node_rank="${POD_RANK}" \
    --rdzv_endpoint="${MASTER_ADDR}:${MASTER_PORT}" \
    --local_addr="$(hostname -I | awk '{print $1}')" \
    /app/train.py
```

## Build your own image

When building your own image, Databricks recommends using `databricks-ai-runtime` skill with a coding agent or starting from a Databricks base image.

### Use a coding agent

Install the `databricks-ai-runtime` Claude Code skill for step-by-step Dockerfile guidance, including building from scratch, CUDA/NCCL/EFA compatibility, common problems, and a pre-build checklist. For requirements and installation options, see [Use agent skills with AI Runtime](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/develop-workloads/coding-agents/agent-skills.md).

```shell
databricks aitools install --skills-only --skills databricks-ai-runtime
```

### <a id="databricks-base-images" />Databricks base images

Databricks publishes base images on Docker Hub at [`databricksruntime/air`](https://hub.docker.com/r/databricksruntime/air/tags) with CUDA, NCCL, and cloud-specific networking (AWS EFA or Azure InfiniBand) preconfigured.

| Tag                         | Variant | CUDA | Use when                                               |
| --------------------------- | ------- | ---- | ------------------------------------------------------ |
| `dcs-base-aws-runtime`      | Runtime | 12   | Installing pre-built wheels only                       |
| `dcs-base-aws-devel`        | Devel   | 12   | Compiling CUDA extensions (requires `nvcc`)            |
| `dcs-base-aws-runtime-cu13` | Runtime | 13   | Installing pre-built wheels only, on CUDA 13           |
| `dcs-base-aws-devel-cu13`   | Devel   | 13   | Compiling CUDA extensions on CUDA 13 (requires `nvcc`) |

Example Dockerfile adding PyTorch to a Databricks base image. The base images provide Python at `/opt/venv`, managed by `uv`. `uv pip install` targets that environment by default; to use a different environment, create and activate a venv before running `uv pip install`.

```dockerfile
FROM databricksruntime/air:dcs-base-aws-runtime

RUN uv pip install --no-cache \
    torch==2.6.0 torchvision==0.21.0 torchaudio==2.6.0

RUN uv pip install --no-cache \
    transformers==4.45.0 \
    accelerate==0.34.0 \
    'mlflow>=3.6'

COPY ./train /app/train
```

Build, push, and register:

```shell
docker build -t myorg/myrepo:mytag .
docker push myorg/myrepo:mytag
air register image myorg/myrepo:mytag --interactive-authenticate -p my-databricks-profile
```

## Requirements

* Images must be hosted on Docker Hub. Amazon ECR, Google GCR, and GitHub GHCR are not supported.
* Image size must be under 20 GB.
* `WORKDIR` is not honored at runtime. Use absolute paths for files baked into the image. For example, use `python /app/train.py`, not `python train.py`.
* You cannot use `environment.dependencies` or `environment.version` with `environment.docker_image.url`. If you need extra packages beyond what is in the image, you must add them to the Dockerfile.

## Troubleshooting

### ssl.SSLError: \[CRYPTO] unknown error (\_ssl.c) when loading dependencies

A custom image can fail at runtime with an OpenSSL error when a library tries to create an SSL context, for example:

```text
ssl.SSLError: [CRYPTO] unknown error (_ssl.c:3076)
```

The error appears while importing libraries that open network connections, such as `huggingface_hub`, and prevents them from loading.

This occurs because `air` workloads run on FIPS-enabled hosts. When the image's cryptographic libraries are not FIPS-compliant, OpenSSL fails to initialize in FIPS mode, so creating an SSL context fails.

**Recommended solution:**

Enterprise, government, healthcare, and finance workloads often depend on FIPS 140-2 or 140-3 compliance for FedRAMP, CMMC, or HIPAA audits. If your workload must remain FIPS-compliant, build your image with FIPS-compliant cryptographic libraries.

If your workload does not require FIPS compliance, you can disable FIPS mode by setting the `OPENSSL_FORCE_FIPS_MODE` environment variable to `0`. Doing so can silently break compliance requirements.

To disable FIPS mode, set it in your workload YAML under `env_variables`:

```yaml
env_variables:
  OPENSSL_FORCE_FIPS_MODE: '0'
```

Alternatively, set the variable in your Dockerfile so it applies to every workload that uses the image:

```dockerfile
ENV OPENSSL_FORCE_FIPS_MODE=0
```

Resubmit the workload and confirm the SSL error no longer appears when dependencies load.

## See also

* [Legacy Python CLI quickstart for AI Runtime](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/connecting/cli/legacy-cli/quickstart.md)
* [Workload YAML reference for the legacy Python CLI](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/connecting/cli/legacy-cli/yaml-config.md)
* [Legacy Python CLI command reference for AI Runtime](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/connecting/cli/legacy-cli/command-reference.md)
