Self-hosted Docker images

Self-hosted Docker images can be useful for reducing the ingress costs, for accelerating image pulls, or for eliminating the dependency on Cortex's public container registry.

In this guide, we'll use ECR as the destination container registry. When an ECR repository resides in the same region as your Cortex cluster, there are no costs incurred when pulling images.

Step 1

Make sure you have the aws, docker and skopeo utilities installed.

Step 2

Export the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables in your current shell, or run aws configure. These credentials must have access to push to ECR.

Step 3

Choose a region for your cluster and ECR repositories. In this guide, we'll assume the region is us-west-2.

Also, take note of your AWS account ID. The account ID can be found in the My Account section of your AWS console.

Step 4

You can use the script below to push the Cortex images to your ECR registry. Make sure to update the ecr_region, aws_account_id, and cortex_version variables at the top of the file. Copy-paste the contents into a new file (e.g., and then run chmod +x, followed by ./ It is recommended to run this from an EC2 instance in the same region as your ECR repository, since it will be much faster.

set -euo pipefail
# user set variables
aws_account_id="620970939130" # example account ID
aws ecr get-login-password --region $ecr_region | docker login --username AWS --password-stdin $destination_registry
# images for the cluster
# images for the APIs (you may delete any images that your APIs don't use)
images=( "${cluster_images[@]}" "${api_images[@]}" )
# create the image repositories
for image in "${images[@]}"; do
aws ecr create-repository --repository-name=$destination_ecr_prefix/$image --region=$ecr_region || true
# pull the images from Docker Hub and push them to ECR
for image in "${images[@]}"; do
if [ "$image" = "python-predictor-gpu-slim" ]; then
for extra_tag in "${extra_tags_for_slim_python_predictor[@]}"; do
echo "copying $image:$cortex_version-$extra_tag from $source_registry to $destination_registry"
skopeo copy --src-no-creds "docker://$source_registry/$image:$cortex_version-$extra_tag" "docker://$destination_registry/$image:$cortex_version-$extra_tag"
echo "copying $image:$cortex_version from $source_registry to $destination_registry"
skopeo copy --src-no-creds "docker://$source_registry/$image:$cortex_version" "docker://$destination_registry/$image:$cortex_version"
echo "###############################################"
echo "add the following images to your cortex cluster configuration file (e.g. cluster.yaml):"
echo "-----------------------------------------------"
for cluster_image in "${cluster_images[@]}"; do
echo "image_$cluster_image_underscores: $destination_registry/$cluster_image:$cortex_version"
echo -e "-----------------------------------------------\n"
echo "use the following images in your API configuration files (e.g. cortex.yaml):"
echo "-----------------------------------------------"
for api_image in "${api_images[@]}"; do
if [ "$api_image" = "python-predictor-gpu-slim" ]; then
for extra_tag in "${extra_tags_for_slim_python_predictor[@]}"; do
echo "$destination_registry/$api_image:$cortex_version-$extra_tag"
echo "$destination_registry/$api_image:$cortex_version"
echo "-----------------------------------------------"

The first list of images that were printed (the cluster images) can be directly copy-pasted in your cluster configuration file before spinning up your cluster.

The second list of images that were printed (the API images) can be used in your API configuration files. The image paths are specified in predictor.image (and predictor.tensorflow_serving_image for APIs with kind: tensorflow). Be advised that by default, the public images offered by Cortex are used for your predictors, so you will need to specify your ECR image paths for all of your APIs.

Step 5

Spin up your Cortex cluster using your updated cluster configuration file (e.g. cortex cluster up --config cluster.yaml).


You can delete your ECR images from the AWS ECR dashboard (set your region in the upper right corner). Make sure all of your Cortex clusters have been deleted before deleting any ECR images.