deploying ML models to the cloud

Deploying ML Models to the Cloud (Basics): From Laptop to Live API

You built a FastAPI app. It validates input and returns predictions in milliseconds. It even documents itself. There’s just one problem: it only runs on your laptop.

That’s exactly where deploying ML models to the cloud comes in. This guide walks through the full companion write-up for Intelevo EP100 on YouTube, where we take that same FastAPI app and give it a real, public address. No advanced DevOps knowledge required. Just one small file, two commands, and a bit of clarity about what “deployment” actually means.

By the end of this article, the whole idea will feel simple. That’s the goal.

Why Your API Needs a New Home

Let’s start with the gap. In EP99, we built a FastAPI app with Pydantic validation and automatic docs. It worked beautifully — but only for you.

Here’s why. FastAPI, by default, listens only on your own machine. Your friend can’t call it. Your phone can’t call it. Even your own laptop can’t reach it once you close the terminal. So the app is real, but it’s invisible to the rest of the internet.

Today, we fix that. We package the app into something the cloud understands. Then we give it a public URL. Anyone, anywhere, can call it after that.

The Analogy That Makes It Click

Before touching any code, let’s borrow an idea from shipping.

Imagine a company sending a product overseas. They don’t ship loose parts and hope the destination has the right shelves. Instead, they pack everything into one sealed container. As a result, any ship, truck, or port in the world can move that container without needing to know what’s inside.

That’s precisely the model for deploying ML models to the cloud. We pack your code, your libraries, and even the correct version of Python into one sealed box. Because that box is sealed and labeled, nobody needs to inspect it to move it. And since it’s built the same way every time, it runs identically on your laptop, on a teammate’s machine, or on a cloud server.

This single analogy explains almost everything that follows. Keep it in mind as we go.

Meet Docker: The Tool That Packs the Box

That sealed container has a name in the software world: a container. And the tool that builds it is called Docker.

Docker reads a short recipe you write once. Then it packs everything your app needs into a box, automatically, every time. Four terms matter here, so let’s define them clearly:

  • Dockerfile — a short text recipe listing what goes inside the box.
  • Image — the actual sealed box, built from that recipe.
  • Container — the image, now running and doing real work.
  • Registry — a shelf in the cloud where images wait until a server picks them up.

Once these four terms feel familiar, the rest of the deployment process becomes mechanical rather than mysterious.

Local vs Cloud: What Actually Changes

It helps to see the difference side by side. Consider these four capabilities:

CapabilityOn Your LaptopIn the Cloud
Who can reach itOnly you, on that machineAnyone with the URL, worldwide
Staying onlineOff when your laptop sleepsRuns continuously
Handling trafficOne process, one paceScales up as demand grows
Getting set upInstall everything by handThe container brings it with it

Notice the pattern. Every row moves from “limited to you” toward “available to everyone.” That shift is the entire point of deployment.

From Code to Live URL in 5 Steps

So what does a real deployment actually involve? Just five steps. And once you complete them once, you’ll repeat them from memory every time after that.

  1. Write a Dockerfile. This is the recipe for your box.
  2. Build the image. Docker turns that recipe into a sealed package.
  3. Push the image to a registry. This places your box on a cloud shelf.
  4. Deploy the service. Your chosen platform takes that image and runs it.
  5. Get your live URL. From this point on, anyone can call your API.

Here’s the encouraging part: your FastAPI code from EP99 stays exactly as it was. Deployment wraps around your code. It never rewrites it. Consequently, everything you already learned about validation, routing, and predictions still applies.

Hands-On Part 1: Writing Your First Dockerfile

Let’s write the recipe. Save this file with the exact name Dockerfile, right next to main.py.

FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

Let’s walk through each line, because every one of them earns its place:

  • FROM python:3.11-slim sets the starting box: a lightweight version of Python 3.11.
  • WORKDIR /app creates and enters a working folder inside that box.
  • COPY requirements.txt . brings your dependency list in first, before anything else.
  • RUN pip install -r requirements.txt installs those dependencies inside the box.
  • COPY . . copies the rest of your application code in.
  • CMD [...] tells Docker how to start your server the moment the container runs.

Now, look closely at that final line. The flag --host 0.0.0.0 is the detail beginners miss most often. Without it, your app only answers itself, even inside the cloud. With it, your app opens the door to the outside world. That one flag is often the difference between “it works” and “nothing loads.”

Hands-On Part 2: Build It, Run It, Call It

With the Dockerfile ready, building and running the container takes just two commands.

docker build -t intelevo-api .
docker run -p 8000:8000 intelevo-api

The first command packs your box and tags it intelevo-api. The second command starts a container from that image. The -p 8000:8000 flag connects a port on your machine to the matching port inside the container. Once it’s running, test it instantly:

curl localhost:8000/health

That last command calls a small endpoint worth adding to your FastAPI app before deployment:

@app.get("/health")
def health_check():
    return {"status": "ok"}

This tiny addition matters more than its size suggests. Cloud platforms constantly check whether your app is alive. Without a health endpoint, they have no reliable way to know. With one, they can detect a crash and restart your service automatically, often before a single user notices anything went wrong.

Choosing a Cloud Home

At this point, your container is ready. The next question is simple: where does it actually live?

You don’t need to master every cloud provider on day one. For your first deployment, pick whichever option gets you a working URL the fastest. Broadly, you have two paths:

Beginner-friendly platforms like Render, Railway, or Fly.io let you point at your Dockerfile and click deploy. They build and host the container for you, and most offer a free tier to start. This is the recommended starting point for anyone deploying an ML API for the first time.

Full cloud providers like AWS, Google Cloud, and Azure offer far more control and scale once you need it. However, they also demand more setup and a steeper learning curve. Save these for when your project genuinely outgrows a simpler platform.

Three Habits That Keep a Deployment Safe

Before you ship anything publicly, build these three habits now. Each one prevents a real, common failure.

  1. Keep secrets out of your code. API keys and passwords belong in environment variables that your platform injects at runtime. Never type them directly into your files.
  2. Add a health check. As shown above, this lets your platform detect a crash and recover automatically.
  3. Bind to 0.0.0.0, not localhost. Localhost only answers itself. 0.0.0.0 opens the door to the outside world.

Together, these three habits cover the majority of first-deployment failures. They take minutes to implement and save hours of confused debugging later.

Three Mistakes First-Timers Make

Even with good intentions, certain mistakes repeat across almost every beginner’s first deployment. Here they are, so you can skip them entirely.

Mistake one: forgetting --host 0.0.0.0. The app runs perfectly on your machine during testing. Then it goes live, and suddenly nothing loads. The fix is one flag, but only if you remember it beforehand.

Mistake two: hardcoding secrets. A key typed directly into main.py has an unfortunate habit of ending up committed to a public repository. Once that happens, rotating the key becomes urgent, not optional.

Mistake three: skipping the health check. Without one, your platform can’t distinguish between a crash and a temporarily busy server. As a result, it won’t attempt automatic recovery, and your users experience unnecessary downtime.

Avoiding these three issues alone puts your first deployment ahead of most beginner attempts.

Why This Actually Matters

It’s worth stepping back and asking: why go through all this?

Reliability improves first. Bad input gets rejected, and crashes get restarted, often before they ever reach a real user.

Scale follows naturally. One container can become ten the moment traffic grows, without rewriting a single line of your original code.

Team speed improves too. Anyone on your team can run the exact same container, so the classic excuse “it works on my machine” simply disappears.

In short, deployment isn’t just a technical checkbox. It’s what turns a personal experiment into something other people, and other systems, can actually depend on.

Why It Feels Simple Once You’ve Done It

Here’s the reassuring truth: once your app is sealed in a container, deploying ML models to the cloud stops being a machine learning problem. It becomes a shipping problem. And shipping a labeled box is simple.

The same container runs on every machine, with nothing behaving differently between them. Most platforms turn your Dockerfile into a live deployment with a single push. From there, the platform handles the rest — restarting it, scaling it, and keeping it alive, all based on that one description you wrote at the start.

A Few Questions You Might Have

Before wrapping up, let’s address a few questions that come up often at this stage.

Does this cost money? Not necessarily. Most beginner-friendly platforms, including Render, Railway, and Fly.io, offer a free tier. That tier is usually enough for a personal project, a portfolio piece, or a small demo. You can always upgrade later, once real traffic demands it.

Do I need Kubernetes for this? No, not yet. Kubernetes manages large fleets of containers across many servers. For your first deployment, a single container on a simple platform is not just sufficient — it’s the right choice. Reach for Kubernetes only when you’re managing dozens of services, not one.

Does this work with scikit-learn, PyTorch, or TensorFlow models? Yes, completely. The container doesn’t care which library trained your model. It only cares that your requirements.txt lists the right dependencies and that your FastAPI code loads the model correctly. Whether your model is a pickled scikit-learn classifier or a saved PyTorch checkpoint, the same Dockerfile pattern applies.

What if my deployment fails on the first try? That’s normal, and it happens to almost everyone. Check three things first: the --host 0.0.0.0 flag, your requirements.txt for missing packages, and your platform’s build logs for the exact error. Nine times out of ten, the fix is small.

With those questions answered, let’s bring everything together.

Quick Recap

Let’s tie everything together:

  • Deployment means packing your app into a sealed, portable container.
  • Docker builds that container from a short recipe called a Dockerfile.
  • The same container runs unchanged on your laptop and in the cloud.
  • A beginner-friendly platform gets you a live URL the fastest for your first deploy.
  • Binding to 0.0.0.0, hiding secrets, and adding a health endpoint keep everything safe.

In one episode, you moved from a bare FastAPI endpoint to a sealed, production-ready API. That’s real progress, and it happened with far less complexity than it first appeared to need.

Watch the Full Walkthrough

This article summarizes the concepts, but the full video walks through every command, every line of code, and every small decision in real time. If you’re deploying your first model, watching along makes the process even clearer.

You’ll find the complete video on the Intelevo YouTube channel. Like the video if it helps, subscribe so you don’t miss the next one, and drop your questions or your own deployment experience in the comments , every comment genuinely shapes what gets covered next.

What’s Next: MLOps and Model Versioning

Your model is live now. But a new question follows immediately: which version is actually running right now?

That’s the exact question EP101 answers. In Introduction to MLOps & Model Versioning, we track every version of your model, so you always know what’s in production and can roll back in seconds if something goes wrong. If this episode made deployment feel manageable, the next one builds directly on that foundation.

See you there.

Leave a Comment

Your email address will not be published. Required fields are marked *