Complete code (including a trained model) to deploy and inference a machine learning model (built on the iris dataset) using Docker and FastAPI.
. |-- Dockerfile |-- README.rst |-- app | |-- model.joblib | `-- server.py |-- client.py `-- requirements.txt
docker build -t image_name .
docker run --name container_name -p 8000:8000 image_name
INFO: Uvicorn running on http://0.0.0.0:8000
Use this url in chrome to see the model frontend; use http://0.0.0.0:8000/docs for testing the model in the web interface.
- Via web interface (chrome):
http://0.0.0.0:8000/docs -> test model
- Via python client:
client.py
- Via curl request:
curl -X POST "http://0.0.0.0:8000/predict" -H "accept: application/json" -H "Content-Type: application/json" -d '{"features": [5.1, 3.5, 1.4, 0.2]}'
docker tag <image-name>:latest | version <docker-hub-username>:<docker-hub-repository-name>:latest | version
docker push <docker-hub-username>:<docker-hub-repository-name>:latest | version