r/FastAPI • • Apr 03 '21

Question Docker deployment not reloading, what am I doing wrong?

Trying to deploy a simple FastAPI web app with Docker but running into an issue when deployed through Docker where my scripts either aren't being called or the endpoint just isn't updating, not sure which.

Aside from the essential imports & instantiation of FastAPI object, my main.py looks like this:

@app.get('/status')
async def status():
    available = checkAvailable() # imported method, calls an external API
    
    if available:
        return {"status" : "free"}
    else:
        return {"status" : "busy"}
if __name__ == '__main__:
    uvicorn.run('app.main:app', port=80, host='0.0.0.0', reload=True)

When I deploy uvicorn locally everything works as expected. Changing availability in the external API & then refreshing the FastAPI properly changes the status.

When deployed via Docker though, the status at the point of the docker image being created is maintained no matter any refresh. My Dockerfile is as follows:

FROM tiangolo/uvicorn-gunicorn-fastapi:python3.8
ENV PYTHONDONTWRITEBYTECODE=1 
ENV PYTHONUNBUFFERED=1
WORKDIR /app/

COPY requirements.txt . 
RUN pip3 --no-cache-dir install -r requirements.txt
COPY . /app/
CMD ["python3", "./app/main.py"]

I've google around and couldn't find anyone talking about having this issue and I really just don't understand if my error is my understanding of FastAPI or Docker, or both.

Any and all help is appreciated. I know there's lots to improve with the app but I'm just starting to learn and want to have a successful deployment of a simple app before digging deeper.

1 Upvotes

Duplicates