A Dockerfile defines the build process for a Docker image containing your and all its dependencies. This page explains how to organize your project files and create a Dockerfile for your Serverless worker.Documentation Index
Fetch the complete documentation index at: https://runpod-b18f5ded-promptless-remove-flash-beta-notification.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
New to Docker? Learn the fundamentals with the introduction to containers tutorial series, which covers creating Dockerfiles, essential Docker commands, and data persistence.
Project organization
Organize your project files in a clear directory structure:project_directory
Dockerfile
src
handler.py
requirements.txt
/Dockerfile/ contains the instructions for building your worker image.
/src/handler.py/ is your .
/requirements.txt/ lists the Python dependencies required by your handler. For example:
requirements.txt
Basic Dockerfile structure
A basic Dockerfile for a Runpod Serverless worker follows this structure:Dockerfile
- Starts with a Python base image.
- Sets the working directory to the root.
- Copies and installs Python dependencies.
- Copies your handler code.
- Specifies the command to run when the container starts.
Choosing a base image
The base image you choose affects your image size, startup time, and available system dependencies. Common options include:Python slim images
Recommended for most use cases. These images are smaller and faster to download:Python full images
Include more system tools and libraries but are larger:images
Required if you need libraries for GPU-accelerated workloads:Custom base images
You can build on top of specialized images for specific frameworks:Including models and files
Baking models into the image
If you need to include model files or other assets in your image, use theCOPY instruction:
Dockerfile
Downloading models during build
You can download models during the Docker build process:Dockerfile
Environment variables
Set environment variables to configure your application without hardcoding values:Dockerfile
Optimizing image size
Smaller images download and start faster, reducing cold start times. Use these techniques to minimize image size:Use multi-stage builds
Multi-stage builds let you compile dependencies in one stage and copy only the necessary files to the final image:Dockerfile
Clean up build artifacts
Remove unnecessary files after installation:Dockerfile
Use .dockerignore
Create a.dockerignore file to exclude unnecessary files from the build context:
.dockerignore
Next steps
After creating your Dockerfile, you can:- Build and deploy your image from Docker Hub.
- Deploy directly from GitHub.
- Test your handler locally before building the image.