Requirements
To deploy a worker image, you need:- A working handler function.
- Docker installed on your development machine.
- A Docker Hub account.
Project organization
Organize your project files in a directory structure like this:requirements.txt file should list all Python packages your handler needs:
Creating a Dockerfile
The Dockerfile tells Docker how to build your worker image. Create a file namedDockerfile (no extension) in your project’s root directory:
Including models and external files
If your handler uses machine learning models or other external files, include them in the Docker image:Building the Docker image
From your terminal, navigate to your project directory and build the Docker image:[DOCKER_USERNAME] with your Docker Hub username, [WORKER_NAME] with a descriptive name for your worker, and v1.0.0 with an appropriate version tag.
The
--platform linux/amd64 flag is required to ensure compatibility with Runpod’s infrastructure.Testing your image locally
Before pushing it to the registry, you should test your Docker image locally:Pushing the image to Docker Hub
Make your image available to Runpod by pushing it to Docker Hub:Image versioning
For production workloads, use SHA tags for absolute reproducibility:- Never rely on the
:latesttag for production. - Use semantic versioning AND SHA tags for clarity and reproducibility.
- Document the specific image SHA in your deployment documentation.
- Keep images as small as possible for faster startup times.
Troubleshooting deployment issues
If your worker fails to start or process requests:- Check the logs in the Runpod console for error messages.
- Verify your handler function works correctly in local testing.
- Ensure all dependencies are properly installed in the Docker image.
- Check that your Docker image is compatible with the selected GPU type.
- Verify your input format matches what your handler expects.
Deploying from AWS ECR
You can deploy Serverless workers from AWS Elastic Container Registry (ECR), but this requires additional setup due to ECR’s credential expiration policy. To deploy from ECR, you’ll need:- An AWS account with ECR access.
- An ECR repository containing your worker image.
- A Runpod account with API access.
Setting up credential automation
ECR credentials expire every 12 hours, so you’ll need to automate credential updates. The recommended approach is to use an AWS Lambda function that refreshes your Runpod container registry credentials:- Create an AWS Lambda function that runs every few hours to refresh ECR credentials.
- Configure the Lambda function to call Runpod’s container registry API to programmatically update stored credentials.
Deploying your ECR image
Once you have credential automation in place:- Push your image to ECR following standard ECR procedures.
- Configure container registry credentials in the Runpod console with your ECR repository URL and current credentials.
- Create your Serverless endpoint using the ECR image URL for the Container Image field:
[AWS_ACCOUNT_ID].dkr.ecr.[REGION].amazonaws.com/[REPOSITORY_NAME]:[TAG]