Deploy with Docker
Build the deployment kit into a container image and run it anywhere Docker runs.
The Docker kit turns one trained model into a container image with a small prediction service inside. The same image runs on your laptop, on a server, and on every container platform in the other deploy guides. You build it yourself, so the model stays in your infrastructure.
Download the Docker kit
Open the Deploy & export panel
On a run page, select Deploy best model. On a model candidate page, open the Deploy & export tab. If the run has several candidates, choose one in the Model menu.
Download the kit
Open the Deploy anywhere tab. On the Docker card, select Download kit. Your browser saves a zip file named <model>_docker_kit.zip.
Unzip it
unzip my-model_docker_kit.zip -d my-model-kit
cd my-model-kitSelect How to deploy on the card to see the same steps in short form. The kit has no credentials in it, and you can generate it again at any time.
What is inside
| File | Purpose |
|---|---|
app.py | The prediction service (FastAPI). |
pipeline.joblib | The fitted model: preprocessing and estimator together. |
input_schema.json | The feature columns the service accepts. It also holds one sample row and is never served. |
sample.json | One example request body. |
requirements.txt | Pinned versions of everything needed to load the model, plus the service. |
Dockerfile, .dockerignore, serve | The container build: non-root user, port 8080, and a health check. |
README.md | Exact commands for your model. |
BUNDLE_README.md, predict.py, model.onnx | The portable bundle. model.onnx is present only when the model family can be converted. |
The Dockerfile starts from a slim Python image whose minor version matches the Python that trained the model. This matters because model files are sensitive to library versions. requirements.txt pins the same versions that were installed where the model was trained.
Build and run
The kit's README.md contains your exact image name and tag. The image name comes from the model's id and the tag from the candidate, so two models never share a tag. The examples below use my-model:v-1.
docker build -t my-model:v-1 .
docker run --rm -p 127.0.0.1:8080:8080 my-model:v-1127.0.0.1: before the port keeps the service reachable from this machine only. This is deliberate: the service has no authentication.
Do not publish the port to the internet
The prediction service does not check who calls it and does not use TLS. To make it reachable by other systems, put a reverse proxy, API gateway or private network in front that authenticates callers.
The service reads these environment variables. All are optional.
| Variable | Default | Meaning |
|---|---|---|
PORT | 8080 | Port the service listens on. |
MAX_BATCH_SIZE | 1000 | Most records accepted in one request. |
MAX_BODY_BYTES | 5242880 (5 MB) | Largest request body accepted. |
Send a prediction
The service has these routes:
| Route | Purpose |
|---|---|
GET /health | Reports that the service is running. |
GET /schema | Returns the column names and data types the model expects. Never returns sample values. |
POST /predict | Returns predictions for a JSON list of records. |
GET /ping, POST /invocations | The same checks and predictions under the names that Amazon SageMaker expects. /invocations also accepts CSV with a header row. |
Send a list of records. Each record must have exactly the columns in input_schema.json: a missing or extra column is refused with status 422. The kit's sample.json is a ready-made request.
curl -X POST http://localhost:8080/predict \
-H "Content-Type: application/json" \
-d @sample.jsonimport json
import requests
records = json.load(open("sample.json"))
response = requests.post("http://localhost:8080/predict", json=records, timeout=30)
response.raise_for_status()
print(response.json())You can also send {"records": [ ... ]} instead of a bare list. The answer has a predictions list with one value per record. For a classification model it also has probabilities (one list per record) and classes (the class labels in the same order as each probability list). For example:
{
"predictions": ["yes"],
"probabilities": [[0.18, 0.82]],
"classes": ["no", "yes"]
}Errors are short and never include internal details. The detailed reason is written to the container logs.
| Status | Meaning |
|---|---|
413 | The body is larger than MAX_BODY_BYTES, or the batch has more than MAX_BATCH_SIZE records. |
422 | The body is not valid JSON, or the records have missing or unexpected columns, or a numeric column holds text. |
500 | The model failed on this input. Read the container logs. |
Health check
GET /health answers {"status": "ok"} as soon as the model is loaded. The Dockerfile already includes a HEALTHCHECK that calls it every 30 seconds, so docker ps shows the container as healthy or unhealthy. Orchestrators can use the same route as a readiness and liveness probe.
curl http://localhost:8080/healthOptional: report predictions to mlflow
The service can send each prediction to mlflow so you can watch volume and drift for a model that runs outside mlflow. It is off unless you set both of these variables, and it never slows down or fails a prediction.
PYCARET_MONITOR_URL=<MONITOR_URL>
PYCARET_MONITOR_KEY=<MONITOR_KEY>Get the values from the Monitor it tab, as described in Monitor models deployed elsewhere. Add --env-file monitor.env to docker run, and keep the file out of version control. The variable names keep a historical prefix; use them exactly as written.
Next steps
Learn the theory
Lessons on learning.mlflow.es that explain the ideas behind this page.
Updated 2026-11-22