This repository provides a Dockerized setup for MLflow, an open-source platform for managing the lifecycle of machine learning projects. The setup includes a PostgreSQL database as the backend store and MinIO for artifact storage.
- MLflow Tracking Server: Centralized platform for managing ML experiments.
- PostgreSQL Backend: Reliable metadata storage.
- MinIO: S3-compatible artifact storage.
- Scalable Architecture: Ready for production use.
- Bucket Setup Automation: Automatically creates required MinIO buckets.
-
Install Docker and Docker Compose:
-
Clone this repository:
git clone https://github.com/Firas-Ruine/mlflow-docker-stack.git cd mlflow -
Create an
.envfile in the root directory with the following content:POSTGRES_USER=postgres POSTGRES_PASSWORD=your_password POSTGRES_DB=mlflow MINIO_ACCESS_KEY=minioadmin MINIO_SECRET_ACCESS_KEY=minioadmin
mlflow/
├── docker-compose.yml # Defines services for MLflow, PostgreSQL, and MinIO
├── .env # Environment variables
├── postgres/
│ └── init.sql # SQL initialization script for PostgreSQL
├── minio/
│ └── create-bucket.sh # Script for creating required MinIO buckets
├── mlflow/
│ └── Dockerfile # MLflow server custom build (optional)
└── README.md # Documentation
Run the following commands to build and start the services:
docker-compose build
docker-compose up -d- MLflow Tracking UI: http://localhost:5000
- MinIO Console: http://localhost:9001
- Username:
minioadmin - Password:
minioadmin
- Username:
The .env file allows you to configure key settings:
- PostgreSQL:
POSTGRES_USER: Username for the database.POSTGRES_PASSWORD: Password for the database.POSTGRES_DB: Database name.
- MinIO:
MINIO_ACCESS_KEY: Access key for MinIO.MINIO_SECRET_ACCESS_KEY: Secret key for MinIO.
The create-bucket.sh script automatically creates the required bucket (mlflow) for storing artifacts.
Here’s an example of how to log experiments with this setup:
import mlflow
# Set the MLflow tracking URI
mlflow.set_tracking_uri("http://localhost:5001")
# Example experiment
with mlflow.start_run():
mlflow.log_param("learning_rate", 0.01)
mlflow.log_metric("accuracy", 0.95)Artifacts will be stored in MinIO under the mlflow bucket.
To stop the containers:
docker-compose downTo remove all containers, networks, and volumes:
docker-compose down -v- Database connection errors: Ensure the
POSTGRES_PASSWORDin.envmatches the--backend-store-uriindocker-compose.yml. - Artifacts not found: Verify that the
mlflowbucket exists in MinIO.
To view service logs:
docker-compose logs <service_name>