This project serves as an educational guide for beginners to set up and run services using Docker and Docker Compose. It focuses on deploying two services:
- MLflow: An open-source platform to manage the machine learning lifecycle.
- Streamlit: A simple framework for building interactive web applications for data projects.
- Introduce beginners to the fundamentals of Docker and Docker Compose.
- Create separate
Dockerfiles for MLflow and Streamlit services. - Launch both services using a
docker-compose.ymlfile.
- Docker installed.
- Docker Compose installed.
- Basic knowledge of Python.
FROM python:3.9-slim
# Install the MLflow library
RUN pip install mlflow
# Set the working directory
WORKDIR /app
# Expose the port
EXPOSE 5001
# Default command to run the MLflow server
CMD ["mlflow", "server", "--host", "0.0.0.0", "--port", "5001"]FROM python:3.9-slim
# Install the Streamlit library
RUN pip install streamlit
# Copy the application file
COPY app.py /app/app.py
# Set the working directory
WORKDIR /app
# Expose the port
EXPOSE 8501
# Default command to run the Streamlit app
CMD ["streamlit", "run", "app.py", "--server.address=0.0.0.0", "--server.port=8501"]# app.py
import streamlit as st
st.title("Simple Streamlit Application")
st.write("Welcome to the MLflow integration interface!")services:
mlflow:
build:
context: .
dockerfile: Dockerfile.mlflow
ports:
- "5001:5001"
streamlit:
build:
context: .
dockerfile: Dockerfile.streamlit
ports:
- "8501:8501"Run the following command:
docker-compose up --build- MLflow: http://localhost:5001
- Streamlit: http://localhost:8501
-
Dockerfile Basics:
- Define the base image (e.g.,
python:3.9-slim). - Install required libraries using
pip install. - Configure ports using
EXPOSE. - Specify default commands with
CMD.
- Define the base image (e.g.,
-
Docker Compose Essentials:
- Combine multiple services into one project.
- Define port mappings and network connections between containers.
- Connect MLflow to a database like MySQL.
- Add a third service such as an API interface using FastAPI.
- Enhance the Streamlit interface to enable interaction with MLflow functionalities.
This project provides a foundational understanding of deploying a multi-service application using Docker. It offers a stepping stone for beginners to build more complex and integrated projects in the future.