Containerized Runtimes with Custom Dockerfiles
Run generic containerized applications on Cerebrium using custom Dockerfiles.
For enhanced flexibility, users can bring existing containerized apps to Cerebrium. These can range from standard Python apps to compiled Rust binaries, provided a functional Dockerfile is supplied to build the app.
There are multiple benefits to building using Dockerfiles on Cerebrium, including the ability to bring existing containerized apps to the platform and maintaining consistent deployment environments that are easily managed locally.
Building Dockerized Python Apps
This example demonstrates a simple FastAPI server that has been containerized:
The application is built using the following Dockerfile:
This is a standard Dockerfile with a CMD
clause that specifies how to run the container. Use this Dockerfile in Cerebrium by referencing it directly in the configuration file.
Update cerebrium.toml to include a custom runtime section with the dockerfile_path
parameter:
The configuration requires three key parameters:
port
: The port the server listens on.healthcheck_endpoint
: The endpoint used to confirm server health. If unspecified, defaults to a TCP ping on the configured port.dockerfile_path
: The relative path to the Dockerfile used to build the app.
If a Dockerfile does not contain a CMD
clause, specifying the entrypoint
parameter in the cerebrium.toml
file is required.
When specifying a dockerfile_path
, all dependencies and necessary commands
should be installed and executed within the Dockerfile. Dependencies listed
under cerebrium.dependencies.*
, as well as
cerebrium.deployment.shell_commands
and
cerebrium.deployment.pre_build_commands
, will be ignored.
Building Generic Dockerized Apps
Cerebrium supports apps in languages other than Python, provided a Dockerfile is supplied. The following example demonstrates a Rust-based API server using the Axum framework:
In this case, a multi-stage Dockerfile is used to separate the build step, creating a smaller and more secure image for the runtime:
Similarly to the FastAPI webserver, the application should be configured in the cerebrium.toml
file: