<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Bhuvaneshwari G</title>
    <description>The latest articles on DEV Community by Bhuvaneshwari G (@bhuvaneshwari_g_9ff3f2d08).</description>
    <link>https://dev.to/bhuvaneshwari_g_9ff3f2d08</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3080265%2Fb28b9945-03db-43f6-baf3-1b19db49d39e.png</url>
      <title>DEV Community: Bhuvaneshwari G</title>
      <link>https://dev.to/bhuvaneshwari_g_9ff3f2d08</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bhuvaneshwari_g_9ff3f2d08"/>
    <language>en</language>
    <item>
      <title>Dockerizing a Python Machine Learning Model</title>
      <dc:creator>Bhuvaneshwari G</dc:creator>
      <pubDate>Fri, 25 Apr 2025 18:09:18 +0000</pubDate>
      <link>https://dev.to/bhuvaneshwari_g_9ff3f2d08/dockerizing-a-python-machine-learning-model-12j</link>
      <guid>https://dev.to/bhuvaneshwari_g_9ff3f2d08/dockerizing-a-python-machine-learning-model-12j</guid>
      <description>&lt;p&gt;In this blog, I’ll walk you through how to create a Python model using the &lt;strong&gt;Iris dataset&lt;/strong&gt;, train it, and then Dockerize it for deployment. Dockerizing a model ensures portability and easy deployment, so let’s get started.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Step 1: Training the Model&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;First, we will load the &lt;strong&gt;Iris dataset&lt;/strong&gt; and train a simple logistic regression model. We’ll use libraries like &lt;strong&gt;pandas&lt;/strong&gt;, &lt;strong&gt;scikit-learn&lt;/strong&gt;, and &lt;strong&gt;joblib&lt;/strong&gt; to do this.&lt;/p&gt;

&lt;p&gt;Here’s the Python code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pandas&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;read_csv&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.linear_model&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;LogisticRegression&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.model_selection&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;train_test_split&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;joblib&lt;/span&gt;

&lt;span class="c1"&gt;# Load the dataset
&lt;/span&gt;&lt;span class="n"&gt;filename&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Iris.csv&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;read_csv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Prepare the features and target
&lt;/span&gt;&lt;span class="n"&gt;array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;
&lt;span class="n"&gt;X&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;[:,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;  &lt;span class="c1"&gt;# Features
&lt;/span&gt;&lt;span class="n"&gt;Y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;[:,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;    &lt;span class="c1"&gt;# Target
&lt;/span&gt;
&lt;span class="c1"&gt;# Split the data into training and testing sets
&lt;/span&gt;&lt;span class="n"&gt;X_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;X_test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Y_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Y_test&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;train_test_split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;test_size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.33&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;random_state&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Train the logistic regression model
&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;LogisticRegression&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max_iter&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Y_train&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Evaluate the model
&lt;/span&gt;&lt;span class="n"&gt;accuracy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;score&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X_test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Y_test&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Model Accuracy: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;accuracy&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;%&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Save the trained model
&lt;/span&gt;&lt;span class="n"&gt;joblib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dump&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;logistic_model.pkl&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This script:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Loads the &lt;strong&gt;Iris dataset&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Splits it into features (X) and target (Y).&lt;/li&gt;
&lt;li&gt;Trains a &lt;strong&gt;logistic regression model&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Saves the model using &lt;strong&gt;joblib&lt;/strong&gt; for later use.&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Step 2: Dockerizing the Model&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Now, we’ll create a &lt;strong&gt;Docker container&lt;/strong&gt; to deploy the model. Docker helps us package our Python environment, ensuring consistency no matter where we run the model.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. &lt;strong&gt;Creating the Dockerfile&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;A &lt;strong&gt;Dockerfile&lt;/strong&gt; defines how to build our Docker image. Here’s the Dockerfile that sets up our Python environment and installs the required libraries:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="c"&gt;# Use a Python base image&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; python:3.8-slim&lt;/span&gt;

&lt;span class="c"&gt;# Set the working directory&lt;/span&gt;
&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /app&lt;/span&gt;

&lt;span class="c"&gt;# Copy the local files into the container&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; . /app&lt;/span&gt;

&lt;span class="c"&gt;# Install dependencies&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--no-cache-dir&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; requirements.txt

&lt;span class="c"&gt;# Expose the port&lt;/span&gt;
&lt;span class="k"&gt;EXPOSE&lt;/span&gt;&lt;span class="s"&gt; 5000&lt;/span&gt;

&lt;span class="c"&gt;# Command to run the model&lt;/span&gt;
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["python", "predict.py"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This Dockerfile:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Uses a lightweight &lt;strong&gt;Python image&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Sets up the working directory and copies files.&lt;/li&gt;
&lt;li&gt;Installs dependencies using &lt;strong&gt;pip&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Exposes port &lt;strong&gt;5000&lt;/strong&gt; for the Flask API (explained next).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. &lt;strong&gt;Creating the requirements.txt&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The &lt;strong&gt;requirements.txt&lt;/strong&gt; file contains the libraries needed for the model and the Flask app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pandas
scikit-learn
joblib
flask
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This file tells Docker which libraries to install in the container.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Step 3: Flask API for Prediction&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Now, we need a Flask API to serve our trained model and handle predictions. Create a &lt;strong&gt;predict.py&lt;/strong&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;joblib&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pandas&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flask&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;jsonify&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Load the model
&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;joblib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;logistic_model.pkl&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/predict&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;methods&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;POST&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;predict&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="c1"&gt;# Get the data from the request
&lt;/span&gt;    &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;force&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;df&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DataFrame&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Make predictions
&lt;/span&gt;    &lt;span class="n"&gt;predictions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;predict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Return the predictions
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;jsonify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;predictions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;tolist&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;debug&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;0.0.0.0&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this API:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We load the &lt;strong&gt;saved model&lt;/strong&gt; using &lt;strong&gt;joblib&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;predict&lt;/strong&gt; endpoint accepts POST requests, takes the input data, and returns predictions from the model.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Step 4: Building and Running the Docker Image&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Let’s build the Docker image and run the container.&lt;/p&gt;

&lt;h4&gt;
  
  
  Build the Docker image:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker build &lt;span class="nt"&gt;-t&lt;/span&gt; iris-model &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Run the Docker container:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-p&lt;/span&gt; 5000:5000 iris-model
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, the model API is up and running on &lt;strong&gt;localhost:5000&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Step 5: Pushing the Docker Image to Docker Hub&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To share your model, push the Docker image to &lt;strong&gt;Docker Hub&lt;/strong&gt;. Here’s how:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Login to Docker Hub&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Tag the Docker image&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker tag iris-model &amp;lt;your-dockerhub-username&amp;gt;/iris-model:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Push the image&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker push &amp;lt;your-dockerhub-username&amp;gt;/iris-model:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This makes your model accessible to anyone with Docker, ready to be deployed anywhere!&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;You’ve just learned how to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Train a machine learning model&lt;/strong&gt; on the Iris dataset.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dockerize&lt;/strong&gt; the model and its environment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deploy&lt;/strong&gt; the model using a Flask API.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Push the Docker image&lt;/strong&gt; to Docker Hub for easy sharing.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This process ensures that your model is portable and ready for deployment. Docker makes it easy to scale and manage models in production.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>python</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Git Good: A Beginner’s Journey Into Advanced Git (With Real Examples)</title>
      <dc:creator>Bhuvaneshwari G</dc:creator>
      <pubDate>Fri, 25 Apr 2025 15:42:25 +0000</pubDate>
      <link>https://dev.to/bhuvaneshwari_g_9ff3f2d08/git-good-a-beginners-journey-into-advanced-git-with-real-examples-2640</link>
      <guid>https://dev.to/bhuvaneshwari_g_9ff3f2d08/git-good-a-beginners-journey-into-advanced-git-with-real-examples-2640</guid>
      <description>&lt;h1&gt;
  
  
  10 Advanced Git Commands You Should Know
&lt;/h1&gt;

&lt;p&gt;Hey folks! 👋&lt;/p&gt;

&lt;p&gt;So after surviving &lt;code&gt;git init&lt;/code&gt;, &lt;code&gt;git add&lt;/code&gt;, and all the noob stuff on Day 1, it’s time to &lt;strong&gt;level up&lt;/strong&gt;. Today, I explored some &lt;strong&gt;advanced Git commands&lt;/strong&gt;, the kind that make you feel like a real dev.&lt;/p&gt;

&lt;p&gt;Here’s a breakdown of 10 Git commands every serious coder should know.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. &lt;code&gt;git diff&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;This command shows the &lt;strong&gt;differences between your commits or files&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git diff
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💬 &lt;em&gt;"You edited something? Git will show you exactly what's different."&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  2. &lt;code&gt;git log&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;This one gives you a detailed &lt;strong&gt;history of your commits&lt;/strong&gt; — author, time, hash, message.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💬 &lt;em&gt;"Kinda like your browser history, but for code. No incognito mode here."&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  3. &lt;code&gt;git clone&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;You can bring a GitHub repo to your local system with this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone &amp;lt;repo-url&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🧠 &lt;em&gt;Note:&lt;/em&gt; If someone made changes to the repo &lt;strong&gt;after you cloned&lt;/strong&gt;, your local copy won’t have those changes unless you pull them.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. &lt;code&gt;git fork&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;When you fork a repo on GitHub, you’re &lt;strong&gt;creating a full copy of someone else's repo&lt;/strong&gt; into &lt;em&gt;your GitHub account&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Useful when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You want to contribute&lt;/li&gt;
&lt;li&gt;You want to customize it as your own&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👨‍🍳 &lt;em&gt;"Think of it like copying your friend’s biryani recipe to your own recipe book and adding extra spice 🌶️."&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  5. &lt;code&gt;git pull&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;It fetches and &lt;strong&gt;merges&lt;/strong&gt; changes from the remote to your local branch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git pull origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💬 &lt;em&gt;"If someone else made changes, this is how you get them."&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  6. &lt;code&gt;git push&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;This uploads your &lt;strong&gt;local commits to GitHub&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git push origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💬 &lt;em&gt;"Think of it as ‘post to Instagram’ but for code."&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  7. &lt;code&gt;git blame&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;This shows who wrote each line of code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git blame &amp;lt;file&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💬 &lt;em&gt;"Want to know who broke the build? Blame 'em. Literally."&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  8. Merge Conflicts 🥲
&lt;/h2&gt;

&lt;p&gt;When two people make conflicting changes in the same file — Git will cry. And so will you.&lt;/p&gt;

&lt;p&gt;Fix it by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reading the conflict markers (&lt;code&gt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&lt;/code&gt;, &lt;code&gt;=======&lt;/code&gt;, &lt;code&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Deciding what to keep&lt;/li&gt;
&lt;li&gt;Committing the resolved file&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;💬 &lt;em&gt;"It’s like two friends editing a group message at the same time… someone’s gonna get mad."&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  9. &lt;code&gt;git branch&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Used to create or list branches.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch feature-x
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💬 &lt;em&gt;"Work on new features without messing up your main code. Like parallel universes, but for bugs."&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  10. &lt;code&gt;.gitignore&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Used to &lt;strong&gt;exclude files/folders&lt;/strong&gt; from being pushed to GitHub.&lt;/p&gt;

&lt;p&gt;Just create a &lt;code&gt;.gitignore&lt;/code&gt; file and list things like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node_modules/
.env
*.log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💬 &lt;em&gt;"Hide your secrets and junk before pushing your repo into the world."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading! Hope this post made advanced Git feel a little less scary and a lot more fun &lt;/p&gt;

</description>
    </item>
    <item>
      <title>11 Essential Git Commands Every Beginner Should Know (With Screenshots)</title>
      <dc:creator>Bhuvaneshwari G</dc:creator>
      <pubDate>Wed, 23 Apr 2025 17:51:42 +0000</pubDate>
      <link>https://dev.to/bhuvaneshwari_g_9ff3f2d08/11-essential-git-commands-every-beginner-should-know-with-screenshots-2ion</link>
      <guid>https://dev.to/bhuvaneshwari_g_9ff3f2d08/11-essential-git-commands-every-beginner-should-know-with-screenshots-2ion</guid>
      <description>&lt;p&gt;&lt;strong&gt;1. git init&lt;/strong&gt;&lt;br&gt;
    Initializes a new Git repo in your current directory.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc3ltu8u853q8huce2ocr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc3ltu8u853q8huce2ocr.png" alt="Image description" width="800" height="37"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Explanation: This command turns the current folder into a Git-tracked project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. git add&lt;/strong&gt;&lt;br&gt;
    Adds files to staging.&lt;br&gt;
    Example: &lt;code&gt;git add .&lt;/code&gt;(adds all files)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fptd4uqaqbqq2zftynutp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fptd4uqaqbqq2zftynutp.png" alt="Image description" width="706" height="41"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Explanation: Staging is like prepping your files before committing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. git commit&lt;/strong&gt;&lt;br&gt;
    Saves changes with a message.&lt;br&gt;
    Example: &lt;code&gt;git commit -m "Initial commit"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvhtr5ftl22oi9cd3s6mc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvhtr5ftl22oi9cd3s6mc.png" alt="Image description" width="800" height="101"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Explanation: It's like hitting "Save" for your project history.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. git status&lt;/strong&gt;&lt;br&gt;
    Shows the current status of files.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjqq1jahum7h4lfamwcvz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjqq1jahum7h4lfamwcvz.png" alt="Image description" width="679" height="92"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Explanation: Tells you what’s been modified, staged, or untracked.&lt;br&gt;
line.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. git log&lt;/strong&gt;&lt;br&gt;
    Shows commit history.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbzj39eg8gqjth225v7k2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbzj39eg8gqjth225v7k2.png" alt="Image description" width="800" height="149"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Explanation: Your project’s time machine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. git branch&lt;/strong&gt;&lt;br&gt;
    Lists all branches.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0huyui5hmiea379uy1so.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0huyui5hmiea379uy1so.png" alt="Image description" width="665" height="78"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Explanation: Also used to create branches: git branch feature-xyz&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. git branch -M&lt;/strong&gt;&lt;br&gt;
    Renames your branch.&lt;br&gt;
    Example: &lt;code&gt;git branch -M main&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fouj5popyekqmqedzuccz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fouj5popyekqmqedzuccz.png" alt="Image description" width="645" height="58"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Explanation: Use it to switch from master to main (the new standard).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. git config user.name&lt;/strong&gt;&lt;br&gt;
    Sets your username.&lt;br&gt;
    Example: &lt;code&gt;git config --global user.name "YourName"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkbwfddo7enpu2pziuel0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkbwfddo7enpu2pziuel0.png" alt="Image description" width="800" height="39"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Explanation: Git will tag commits with this name.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;9. git config user.email&lt;/strong&gt;&lt;br&gt;
    Sets your email.&lt;br&gt;
    Example: &lt;code&gt;git config --global user.email "you@example.com"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5di1ltwpd6icfejg8ob5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5di1ltwpd6icfejg8ob5.png" alt="Image description" width="800" height="41"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Explanation: GitHub uses this to link commits to your account.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;10. git remote add origin&lt;/strong&gt;&lt;br&gt;
      Connects your repo to GitHub.&lt;br&gt;
      Example: &lt;code&gt;git remote add origin https://github.com/yourusername/yourrepo.git&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4pxydpkoudhw5cww6k97.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4pxydpkoudhw5cww6k97.png" alt="Image description" width="800" height="23"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Explanation: This sets the destination where you push your code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;11. git push&lt;/strong&gt;&lt;br&gt;
      Sends your commits to GitHub.&lt;br&gt;
      Example: &lt;code&gt;git push -u origin main&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fafithdlht6ts4a0jzq6k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fafithdlht6ts4a0jzq6k.png" alt="Image description" width="800" height="249"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Explanation: Think of it as uploading your progress online.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AHH! Finally!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffh53wuc4d9gtjuy0koif.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffh53wuc4d9gtjuy0koif.png" alt="Image description" width="800" height="298"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>github</category>
    </item>
  </channel>
</rss>
