Docker¶
The image serves the REST API with a gradient-boosting regressor and classifier.
Then open http://localhost:8000/docs.
How the image is built¶
- Two stages. The builder installs
amesml[api]into a virtual environment and prepares the models; the runtime stage copies only the environment and the two model directories onto a cleanpython:3.11-slim. - Models. If
models/regression-gbmandmodels/classification-gbmexist in the build context they are used as they are. Otherwise they are trained fromdata/train.csvduring the build, so the image always starts with working models. - Small context.
.dockerignoreis an allowlist: onlypyproject.toml,README.md,LICENSE,src/,data/andmodels/are sent to the build. - Non-root. The service runs as an unprivileged
amesmluser. - Health check. Docker polls
GET /health.
Serving other models¶
Mount a model directory and point AMESML_MODEL_PATH at it:
docker run --rm -p 8000:8000 \
-v "$(pwd)/models/regression-linear:/models/regression-linear:ro" \
-e AMESML_MODEL_PATH=/models/regression-linear \
amesml
Note
A model trained outside the container may have been pickled with a different scikit-learn version. scikit-learn warns about this when loading; the safest course is to train inside the same image.