- Virtual environment
- Install dependencies
- Start the Flask server
docker-compose
- Docker Hub
- Remove Docker images and containers
- Pull the image from Docker Hub and run
conda create -n your_env_name python=3.11 -y # create a virtual environment
conda activate your_env_name # activate your virtual environment
cd app/api # head to where the requirements.txt is located
conda install --file requirements.txt -y # install dependencies
python app.py
curl -X POST -H "Content-Type: application/json" -d '{"text": "May the Force be with you."}' 0.0.0.0:5000/predict
{
"label": "Positive",
"pred": 1,
"text": "May the Force be with you."
}
Build the image then run the container based on that image.
docker compose up --build
-
Change the request method to
POST
and set the endpoint tohttp://localhost:5000/predict
in Postman. -
Under the
Headers
tab, typeContent-Type
for the key andapplication/json
for the value. -
Under the
Body
tab, selectraw
and enter the following:{ "text": "May the Force be with you." }
-
Hit send and you will see the same output as above during production
docker compose push
docker images # view all images
docker rmi -f <IMAGE_ID> # remove image
docker ps -a # list all containers
docker rm -f <CONTAINER_ID> # remove container
Now that your local is clean, let's confirm that we successfully pushed the Docker image into Docker Hub by running the following:
docker run -p5000:5000 your_username/your_app_name
You can follow the same steps above and test with Postman to confirm that it is working as expected.