I made a FastAPI API service with routes per "endpoint sort", which works fine running it locally through the terminal using "uvicorn main:app --reload". Running it using Docker-compose works fine as well. (see screenshot for file structure)
Whenever i try to build an image and do "docker run myimage" it starts up and displays the address: http://0.0.0.0:8000. Sending requests to it however doesn't seem to work for some reason. Why does "Docker-compose" work and "Docker Run" not?
I need a docker image that i can deploy on Google Cloud run. I'm relatively new to Docker so this seems like complete magic to me. Would love to understand what i did wrong here.
my Dockerfile:
FROM python:3.8.10
COPY ./app /app
RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt
RUN apt-get update
RUN apt-get --yes install libsndfile1-dev
EXPOSE 8000
CMD uvicorn app.main:app --host 0.0.0.0 --port 8000
my Docker-compose file:
version: '3.3'
services:
app:
build: .
command: uvicorn app.main:app --host 0.0.0.0 --port 8000
ports:
- "8000:8000"
my main.py:
from fastapi import FastAPI
import uvicorn
import os
from app.routes.api import router as api_router
app = FastAPI()
app.include_router(api_router)
@app.get('/')
def index():
return {'message': 'Everything online'}