
MLflow is an open-source platform for tracking machine learning experiments, managing models, and storing artifacts across the machine learning lifecycle. It enables teams to centralize experiment metadata, compare results, and reproduce experiments reliably. MLflow supports S3-compatible object storage for storing trained models, datasets, and experiment outputs in a durable and scalable backend.
This article explains how to deploy MLflow on a Linux server using Docker Compose, configure Traefik for automatic HTTPS with Let's Encrypt, enable basic authentication for secure access, integrate S3-compatible object storage for artifact storage, and demonstrate logging a sample machine learning experiment.
Before you begin, you need to:
mlflow.example.com).MLflow requires configuration for database storage, artifact storage, domain routing, and HTTPS certificates. These settings are defined using environment variables and consumed by Docker Compose during deployment. Storing them in a .env file keeps sensitive credentials separate from the compose manifest and simplifies configuration management.
Create the project directory.
Navigate to the project directory.
Create the environment file.
Add the following environment variables:
Replace:
mlflow.example.com with your domain name that points to your server IP address.admin@example.com with your email address for Let's Encrypt notifications.StrongDatabasePassword123 with a secure password for PostgreSQL.GENERATED_SECRET_KEY with a random string generated using openssl rand -hex 32.mlflow-artifacts with your Object Storage bucket name.YOUR_ACCESS_KEY with your S3 access key.YOUR_SECRET_KEY with your S3 secret key.YOUR_REGION with the storage region (for example, ewr1).YOUR_OBJECT_STORAGE_ENDPOINT with the S3-compatible endpoint provided by your cloud provider (for example, ewr1.vultrobjects.com).Save and close the file.
This deployment uses Docker Compose to run PostgreSQL as the backend for MLflow metadata and the MLflow server for experiment tracking. Traefik acts as a reverse proxy that handles HTTPS termination, domain-based routing, and automatic TLS certificate provisioning. MLflow's built-in basic authentication secures access to the web interface and API.
Create the authentication configuration file.
Add the following configuration:
Replace ADMIN_PASSWORD with a strong password for the admin account (must be longer than 12 characters), then save and close the file.
Create the MLflow Dockerfile. The base MLflow image requires additional dependencies for PostgreSQL, S3 storage, and authentication.
Add the following configuration:
Save and close the file.
Create the Docker Compose configuration file.
Add the following configuration:
Save and close the file.
In the above manifest:
services: Launches three containers managed by Docker Compose:traefik: Serves as the reverse proxy and TLS termination point.postgres: Stores MLflow metadata in a persistent database.mlflow: Runs the MLflow server with authentication, PostgreSQL backend, and S3-compatible object storage.build (mlflow): Builds the MLflow image from the local Dockerfile with PostgreSQL, S3, and authentication dependencies.environment (mlflow): Configures S3-compatible object storage credentials and authentication settings. MLFLOW_AUTH_CONFIG_PATH points to the authentication configuration file, and MLFLOW_FLASK_SERVER_SECRET_KEY secures session cookies.command (mlflow): Starts the MLflow server with --app-name basic-auth to enable username/password authentication. The --serve-artifacts flag enables artifact proxying, and --allowed-hosts restricts access to the configured domain.volumes (mlflow): Mounts the authentication configuration file and persists the authentication database.expose: Makes port 5000 available internally for Traefik routing without exposing it to the host network.labels: Registers the MLflow container with Traefik for HTTPS routing on the configured domain.depends_on: Ensures MLflow starts only after PostgreSQL becomes healthy.volumes: The ./letsencrypt bind mount stores TLS certificates, ./postgres_data persists PostgreSQL data, and ./mlflow_auth persists the authentication database across container restarts.restart: unless-stopped: Enables automatic recovery after failures or server reboots.Build and start the containers in detached mode.
Verify all services are running.
The output displays three running containers: Traefik, PostgreSQL, and MLflow with Traefik listening on ports 80 and 443.
View the logs for any errors.
For more information on managing Docker Compose stacks, see the How to Use Docker Compose article.
After deploying MLflow with Docker Compose, access the web interface to verify the deployment and authentication are working correctly.
Open your web browser and navigate to https://mlflow.example.com. Replace mlflow.example.com with your configured domain.
Enter the admin username and password configured in basic_auth.ini when prompted.
Verify that the MLflow dashboard loads. The interface displays a Welcome page with Getting Started options, navigation sidebar with Home, Experiments, Prompts, and AI Gateway, and a Recent Experiments section showing the Default experiment.
MLflow tracks experiments by logging parameters, metrics, and artifacts to the server. The following example trains an ElasticNet regression model on the Diabetes dataset and records the results.
Install the Python virtual environment package.
Create and activate a virtual environment.
Install the required Python packages.
This command installs the Python packages required for running ML experiments:
mlflow: Tracks experiments, logs metrics, parameters, and artifacts.scikit-learn: Provides tools for building and evaluating machine learning models.pandas: Handles data manipulation using DataFrame structures.numpy: Supports numerical computations and array operations.boto3: Enables MLflow to store artifacts in S3-compatible storage.Create a Python script for the experiment.
Add the following code, adapted from the official MLflow example. Replace mlflow.example.com in the code with your actual domain.
Save and close the file.
Set environment variables for MLflow authentication and S3 storage.
Replace:
ADMIN_PASSWORD with the password configured in basic_auth.ini.YOUR_ACCESS_KEY with your S3 access key.YOUR_SECRET_KEY with your S3 secret key.YOUR_OBJECT_STORAGE_ENDPOINT with your S3-compatible endpoint.Run the experiment.
Open the MLflow UI in your browser at https://mlflow.example.com. The official_demo_experiment appears in the Experiments list.
Click the experiment to view the run details. The run displays:
alpha and l1_ratio values used for training.rmse and r2 evaluation scores.Verify that artifacts are stored in your Object Storage bucket by checking the bucket contents in your cloud provider's dashboard.
You have deployed MLflow with Docker Compose using Traefik for automatic HTTPS and basic authentication for secure access. The setup provides a fully functional experiment tracking platform with a PostgreSQL backend, Object Storage artifact management, and a protected web interface accessible via your domain. You can log experiments, track parameters and metrics, and store artifacts in a centralized location. For advanced usage, user management, or further customization, visit the official MLflow documentation.
0 Comments
Be the first to comment and share your perspective with the community.