Skip to main content

How to Run an MLflow Model in a Docker Container

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

An image from mlflow models build-docker serves its model on port 8080 inside the container. docker run starts it, and -p connects a port on your computer to that 8080, so requests reach the model the same way as with mlflow models serve. This guide runs one in the background, waits for it, asks it for a prediction, and stops it, with real output from MLflow 3.18.0 and Docker Desktop 4.100.1.

Syntax​

Syntax
docker run -d --name NAME --platform linux/amd64 -p 127.0.0.1:HOST_PORT:8080 IMAGE
PartWhat it means
-dRun in the background and print the container's ID
--name NAMEA name to use in later commands, instead of the ID
--platform linux/amd64The image's platform; MLflow builds every image for it, and saying so avoids a warning on Apple silicon
-p 127.0.0.1:HOST_PORT:8080Connect HOST_PORT on your computer, and only on your computer, to the container's port 8080
IMAGEThe image's name, such as fitness-weight

The build-docker reference runs it as docker run -p 5001:8080 "my-image-name". The same commands work in PowerShell.

Prerequisites​

  • Docker Desktop, running. It's free for personal use, education, non-commercial open source and small businesses, under Docker's licence terms.
  • An image of a model, built with mlflow models build-docker: How to Build a Docker Image for an MLflow Model. This guide uses fitness-weight, a linear regression that predicts a man's weight from his chin-ups, sit-ups and jumps, built from models:/m-74c4e5b1f02e48b4912c4d4fffe9a12b with -n fitness-weight --env-manager local.

Step 1: Start the Container​

Terminal
docker run -d --name fitness-api --platform linux/amd64 -p 127.0.0.1:5002:8080 fitness-weight
Output
370bb5839d1cbfab8e28466e3e023073c644c86a090ddd2bf1dac42b68710acf

The long number is the container's ID; fitness-api works the same in later commands. The container answers on http://127.0.0.1:5002, and only from this computer, because the port is published on 127.0.0.1.

Step 2: Wait Until It's Ready​

Right after docker run, the container isn't listening yet:

Terminal
curl -i http://127.0.0.1:5002/ping
Output
curl: (52) Empty reply from server

For the next seconds, nginx answers but the model server behind it is still starting, so /ping gets 502 Bad Gateway. After about 20 seconds:

Output
HTTP/1.1 200 OK
Server: nginx/1.26.3
Date: Thu, 26 Nov 2026 05:16:39 GMT
Content-Type: application/json
Content-Length: 1
Connection: keep-alive

curl -i's output in a terminal: HTTP/1.1 200 OK from Server nginx/1.26.3 for /ping on port 5002.

200 OK, from nginx: the model is loaded. A loop that asks /ping until it answers is in How to Check That an MLflow Model Server Is Running.

Step 3: Ask for a Prediction​

Terminal
curl http://127.0.0.1:5002/invocations -H "Content-Type: application/json" --data '{"dataframe_records": [{"Chins": 5, "Situps": 162, "Jumps": 60}]}'
Output
{"predictions": [176.17362115123967]}

A predicted weight of about 176 pounds, the same request format as mlflow models serve.

Step 4: Read the Logs​

Terminal
docker logs fitness-api
Output (excerpt)
172.17.0.1 - - [26/Nov/2026:05:16:19 +0000] "GET /ping HTTP/1.1" 502 157 "-" "curl/8.7.1"
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started parent process [21]
...
INFO: Started server process [33]
INFO: Waiting for application startup.
INFO: Application startup complete.
...
172.17.0.1 - - [26/Nov/2026:05:16:39 +0000] "GET /ping HTTP/1.1" 200 1 "-" "curl/8.7.1"

docker logs' output in a terminal: nginx's 502 for an early /ping, uvicorn running on 127.0.0.1:8000 with a parent process, worker processes starting, and nginx's 200 for /ping.

Two programs write here: nginx, with lines like "GET /ping HTTP/1.1" 502, and uvicorn, the model server on port 8000 inside the container, with its INFO: lines. The 502 lines are the requests that came before the model server was ready. The image starts one worker per CPU by default, ten on this computer: How to Set the Number of Workers in an MLflow Model Container.

Step 5: Stop and Remove the Container​

Terminal
docker stop fitness-api
docker rm fitness-api
Output
fitness-api
fitness-api

docker stop asks the container to shut down, and docker rm deletes it. The image stays, ready for the next docker run.

Common Mistakes​

MistakeWhat happensDo this instead
-p 5002:5002Nothing in the container listens on 5002The container's side is always 8080
-p 5002:8080 without 127.0.0.1The model is reachable from your whole network-p 127.0.0.1:5002:8080 on your own computer
Calling /health or /version on the container404 and {}: nginx passes on only /ping and /invocationsFixed: An MLflow Model Container Answers 404 for /health and /version

Troubleshooting​

SymptomLikely causeFix
curl: (52) Empty reply from serverThe container is still startingWait a few seconds
502 Bad Gatewaynginx is up, the model server isn't yetWait until /ping answers 200
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform--platform is missing on an Apple silicon MacFixed: The requested image's platform does not match

FAQ​

Why does the model server say 127.0.0.1:8000?​

That's inside the container: nginx listens on 8080 and passes requests to uvicorn on 8000. Only 8080 is meant to be published.

Does removing the container remove the model?​

No: the model is in the image, and docker rm deletes only the container. The next docker run of fitness-weight serves it again.

Conclusion​

docker run -d --name fitness-api --platform linux/amd64 -p 127.0.0.1:5002:8080 fitness-weight started the model's container in the background. /ping answered 200 after about 20 seconds, a prediction came back from /invocations, docker logs showed nginx and the model server's workers, and docker stop and docker rm removed the container, leaving the image.

Additional Resources​