Problem running fastapi app Mac M1 chip

Hi, 1st time posting here :slight_smile:
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:
Screen Shot 2022-09-18 at 2.00.16

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)

It would be very useful if you could share any information about your problem. The only information you shared is that you have a problem and

Please, don’t share screenshots of codes either. Share the code as text and use code blocks (</> button above the message text area)

Also note that if you post new comments instead of editing your first post, your topic will look like someone started to help you, so it is more likely that people will ignore the topic when they only have time to answer one or two questions.

1 Like

Thank you, will do right away :slight_smile: