30
loading...
This website collects cookies to deliver better user experience
pip3 install virtualenv
python3 -m virtualenv hello-app-env
source hello-app-env/bin/activate
pip3 install fastapi uvicorn
pip3 freeze > requirements.txt
main.py
in your src
directory and add the following code:/src/main.py
from fastapi import FastAPI
app = fastAPI()
@app.get("/")
def index():
return {"Greeting": "Hello World!"}
Dockerfile
FROM python:3.9
COPY ./src /app/src
COPY requirements.txt /app
WORKDIR /app
RUN pip3 install -r requirements.txt
EXPOSE 8000
CMD ["uvicorn", "main:app", "--host=0.0.0.0", "--reload"]
--reload
will automatically update changes when made so you won't have to re-run the container.docker build -t hello-world-env .
docker run -p 8000:8000 --name hello-app hello-world-env
docker image ls
docker container ls
docker run
command will spin up your local server and you can view your results through this URL http://localhost:8000 or http://127.0.0.1:8000 ``