Runpod’s GPU Pods use custom Docker images to run your code. This means you can’t directly spin up your own Docker instance or build Docker containers on a GPU Pod. Tools like Docker Compose are also unavailable. This limitation can be frustrating when you need to create custom Docker images for your Runpod templates. Fortunately, many use cases can be addressed by creating a custom template with the desired Docker image. In this tutorial, you’ll learn how to use the Bazel build tool to build and push Docker images from inside a Runpod container. By the end of this tutorial, you’ll be able to build custom Docker images on Runpod and push them to Docker Hub for use in your own templates.Documentation Index
Fetch the complete documentation index at: https://runpod-b18f5ded-promptless-github-integration-timeout-clari.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
Before you begin this guide you’ll need the following:- A Docker Hub account and access token for authenticating the docker login command
- Enough volume for your image to be built
Create a Pod
- Navigate to Pods and select + Deploy.
- Choose between GPU and CPU.
-
Customize your an instance by setting up the following:
- (optional) Specify a Network volume.
- Select an instance type. For example, A40.
- (optional) Provide a template. For example, Runpod Pytorch.
- (GPU only) Specify your compute count.
- Review your configuration and select Deploy On-Demand.
- Select Connect.
- Choose Start Web Terminal and then Connect to Web Terminal.
- Enter your username and password.
Clone the example GitHub repository
Clone the example code repository that demonstrates building Docker images with Bazel:Install dependencies
Install the required dependencies inside the Runpod container: Update packages and install sudo:- Go to https://hub.docker.com/settings/security and click “New Access Token”.
- Enter a description like “Runpod Token” and select “Read/Write” permissions.
- Click “Generate” and copy the token that appears.
- In the terminal, run:
Configure the Bazel Build
First, install nano if it’s not already installed and open theBUILD.bazel file for editing:
BUILD.bazel
{YOUR_USERNAME} placeholder with your Docker Hub username in the BUILD.bazel file:
BUILD.bazel
Build and Push the Docker Image
Run the bazel command to build the Docker image and push it to your Docker Hub account:custom_image containing the Docker image you just built.
You can now reference this custom image in your own Runpod templates.