Hi, 1st time posting here
having a problem running fastapi app with a single docker file or with docker compose (contains Jupyter notebook to run the commands of the fast api app)
Until this stage it seems like every thing is supposed to be OK,
locally the app runs and all the logics/routes work perfectly.
I guess I’m configuring something wrong.
this is my directory tree:
DockerFile:
# temp stage
FROM python:3.9-slim as builder
WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
RUN apt-get update && \
apt-get install -y --no-install-recommends gcc
COPY requirements.txt .
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /app/wheels -r requirements.txt
# final stage
FROM python:3.9-slim
WORKDIR /app
COPY --from=builder /app/wheels /wheels
COPY --from=builder /app/requirements.txt .
COPY . /app
RUN pip install --no-cache /wheels/*
CMD [ "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080" ]
docker-compose:
version: "3.9"
services:
jupyter:
image: jupyter/scipy-notebook
ports:
- "8888:8888"
volumes:
- ./notebooks:/home/jovyan/
environment:
JUPYTER_ENABLE_LAB: "yes"
command: "start-notebook.sh --NotebookApp.token='' --NotebookApp.password=''"
axonius-scraper:
build: .
ports:
- "8080:8080"
fastapi app:
from fastapi import FastAPI
import uvicorn
from xxxx_api.api.name.controller import run_names_flow
from xxxx_api.api.age.controller import validate_birthday
from xxxx_api.api.blood.controller import validate_donor
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello World"}
@app.get("/api/top_used_words")
async def top_used_words(number_of_names: int = 100):
return await run_names_flow(number_of_names)
@app.get("/api/old_person")
def old_person():
return validate_birthday()
@app.get("/api/get_blood_donors")
def get_blood_donors(blood_type: str):
return validate_donor(blood_type)
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8080)