Custom Dockerfiles
Run generic containerized applications on Cerebrium using your own 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:
When creating a Dockerfile for Cerebrium, there are three key requirements:
- You must expose a port using the
EXPOSE
command - this port will be referenced later in yourcerebrium.toml
configuration - A
CMD
command is required to specify what runs when the container starts (typically your server process) - Set the working directory using
WORKDIR
to ensure your application runs from the correct location (defaults to root directory if not specified)
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: