Applications on Beam are run inside containers. A container is a lightweight VM that packages a set of software packages required by your application.

Containers are based on container images which are instructions for how a container should be built.

Because you are building a custom application, it is likely that your application depends on some custom software to run.

You can customize the container image used to run your Beam application with the Image parameter.

Beam containers have two defaults to be aware of:

Default Container OS: Ubuntu 20.04

Default CUDA: CUDA 12.2

Adding custom base images

You can import existing images from remote Docker registries, like Dockerhub, Google Artifact Registry, ECR, Github Container Registry, Nvidia and more.

Just supply a base_image argument to Image.

from beam import endpoint, Image


image = (
    Image(
        python_version="python3.9",
        python_packages=[
            "transformers",
            "torch",
        ],
        commands=["apt-get update -y && apt-get install ffmpeg -y"],
        base_image="docker.io/nvidia/cuda:12.3.1-runtime-ubuntu20.04",
    ),
)


@endpoint(cpu=1, memory="16Gi", gpu="T4", image=image)
def handler():
    return {}
Beam only supports Debian-based images.

Adding shell commands

You can also run any shell commands you want in the environment before it starts up. Just pass them into the commands field in your app definition.

Below, we’ll customize our image with requests and some shell commands:

from beam import endpoint, Image


image = (
    Image(
        python_version="python3.9",
        python_packages=["requests"],
        commands=["apt-get update && pip install beautifulsoup4"],
    ),
)


@endpoint(cpu=1, memory="16Gi", gpu="T4", image=image)
def handler():
    return {}

Adding Python packages

You can add Python packages to the runtime in the python_packages field:

from beam import Image


image = (
    Image(
        python_version="python3.9",
        python_packages=["requests"],
    ),
)
Beam will default to Python 3.8 if no python_version is provided.

Alternatively, you can pass in a path to a requirements.txt file:

from beam import Image


image = (
    Image(
        python_packages="requirements.txt",
    ),
)