- Build the Docker Image
$ docker build -t fastapi-ml .- Start the container:
$ docker run -p 80:80 fastapi-ml- Test the Docker container with an example request:
-
Option 1: Using the web browser.
Visit
http://0.0.0.0:80/docs. You will see a /predict endpoint:
You can click on "Try it now" which will let you modify the input request. Click on "Execute" to see the model prediction response from the web server.
- Option 2: Using the command line:
$ curl -X 'POST' \
'http://0.0.0.0/predict' \
-H 'Content-Type: application/json' \
-d '{
"DepartureDateTime": "12/12/2022 15:15:15",
"Origin":"JFK",
"Destination":"ATL"
}'- Find out the container id of the running container:
$ docker psThis will return a response like the following:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f9b59902e94f fastapi-ml "uvicorn main:app --…" 10 minutes ago Up 10 minutes 0.0.0.0:80->80/tcp brave_liskov- SSH into the container using the container id from above:
$ docker exec -it <container id> /bin/sh- Tail the logs:
$ tail -f ../data/logs.out- Now when you send any request to the web server (from the browser, or another tab in the command line), you can see the log output coming through in
logs. Test the web server with these requests and make sure you can see the outputs inlogs:
{
"DepartureDateTime": "24/12/2023 19:15:00",
"Origin":"JFK",
"Destination":"ATL"
}{
"DepartureDateTime": "01/01/2023 15:15:00",
"Origin":"DTW",
"Destination":"JFK"
}{
"DepartureDateTime": "04/07/2022 09:15:00",
"Origin":"SEA",
"Destination":"ATL"
}{
"DepartureDateTime": "12/12/2022 22:30:00",
"Origin":"DTW",
"Destination":"MSP"
}