A project to test FastAPI and Docker.
Language: Python
Start: 2023
I wanted to test FastAPI to create a simple API server. I took this opportunity also to try Docker. Therefore, I packaged the Python project in a Docker container and moved it to a Google Cloud machine.
Example of output of one of the get command:
- python3 -m venv venv
- . venv/bin/activate
- pip install (all necessary packages including -of course- FastAPI)
- pip freeze > requirements.txt
- docker build -t python-fastapi .
- docker run -p 8000:8000 python-fastapi
- docker run -p 8000:8000 --detach python-fastapi
- docker run -p 8000:8000 --mount type=bind,source="$(pwd)"/../external.txt,target=/mypath/external.txt,readonly python-fastapi
- read the project ID on Google (e.g., google-id)
- gcloud auth configure-docker
- docker tag python-fastapi eu.gcr.io/google-id/python-fastapi
- docker push eu.gcr.io/google-id/python-fastapi
- created an ad hoc VM mounting the docker image present in the Container Registry