Container Support with fal
fal now supports running functions within custom Docker containers, providing greater flexibility and control over your environment.
Example: Using Custom Containers with fal functions
Here’s a complete example demonstrating how to use custom containers with fal
.
Detailed Explanation
- Importing fal and ContainerImage:
- Creating a Dockerfile String:
A multi-line string (
dockerfile_str
) is defined, specifying the base image aspython:3.11
, and installingffmpeg
andpyjokes
packages.
Alternatively, you can use a Dockerfile path to specify the Dockerfile location:
-
Defining the Container Function: The
@fal.function
decorator specifies that this function runs in a container. Theimage
parameter is set usingContainerImage.from_dockerfile_str(dockerfile_str)
, which builds the Docker image from the provided Dockerfile string. -
Function Implementation: Inside
test_container
, theffmpeg
library processes a video to create a thumbnail image. Then, it usespyjokes
to print a random joke.
Running the Function
To run the function, save the code to a file (e.g., test_container.py
) and execute it using the fal run
command:
or directly from the Python interpreter:
This example demonstrates how to leverage Docker containers in fal, enabling customized execution environments for your functions. For more details and advanced usage, refer to the fal Container Documentation.