Dockerizing APIs
To save time during production and ease the deployment process, it is essential to use Docker. It is very important to isolate your service and application. Also, note that the same code can be run anywhere, regardless of the underlying OS. To achieve this, Docker provides great functionality and packaging. Before using it, you must install it using the steps recommended in the Docker documentation (https://docs.docker.com/get-docker/):
- First, put the
main.py
file in the app directory. - Next, you must eliminate the last part from your code by specifying the following:
if __name__ == '__main__': uvicorn.run('main:app', workers=1)
- The next step is to make a Dockerfile for your fastAPI; you made this previously. To do so, you must create a Dockerfile that contains the following content:
FROM python:3.7 RUN pip install torch RUN pip install fastapi uvicorn transformers EXPOSE 80 COPY ./app /app CMD ["uvicorn...