0
0
MLOpsdevops~30 mins

Docker for ML reproducibility in MLOps - Mini Project: Build & Apply

Choose your learning style9 modes available
Docker for ML reproducibility
📖 Scenario: You are a data scientist working on a machine learning project. You want to make sure your code runs the same way on any computer. This helps your team avoid problems when sharing your work.Docker is a tool that packages your code, libraries, and settings into one container. This container works the same everywhere.
🎯 Goal: Build a simple Docker setup that runs a Python script for training a machine learning model. You will create a Dockerfile, add a configuration, run the training script inside the container, and see the output.
📋 What You'll Learn
Create a Python script named train.py that prints a message about training.
Write a Dockerfile that uses Python 3.12 image and copies train.py inside.
Add a configuration variable inside train.py to set the number of training epochs.
Run the training script inside the Docker container and print the training message with epochs.
💡 Why This Matters
🌍 Real World
Data scientists use Docker to share ML projects that run the same on any computer or cloud.
💼 Career
Knowing Docker helps ML engineers and DevOps teams ensure reproducible and reliable ML workflows.
Progress0 / 4 steps
1
Create the training script
Create a Python file named train.py with a variable message set to the string "Training model..." and a print statement that prints message.
MLOps
Need a hint?

Use a variable called message and set it to the exact string. Then print it.

2
Write the Dockerfile
Create a file named Dockerfile that starts with FROM python:3.12-slim, copies train.py into the container, and sets the command to run python train.py.
MLOps
Need a hint?

Use the official Python 3.12 slim image. Copy the script and set the working directory. Use CMD to run the script.

3
Add training epochs configuration
In train.py, add a variable epochs set to 5. Change the print statement to print f"Training model for {epochs} epochs..." using an f-string.
MLOps
Need a hint?

Remove the old message variable. Use epochs = 5 and an f-string in print.

4
Run the Docker container and show output
Run the Docker container using the command docker build -t ml-train . to build the image, then docker run ml-train to run it. Write a print statement in your script that outputs exactly Training model for 5 epochs....
MLOps
Need a hint?

Make sure your print statement matches the output exactly. Build and run the Docker container as instructed.