Search code examples
pythondockerfastapiuvicorn

FastAPI uvicorn server does not show logs in docker container


I have a docker container with a conda enviroment created inside it to handle all of my dependencies. When I run an interactive shell, uvicorn server logs are shown, nut running it in daemon mode show no logs, and keep getting an internal server error I don't know how to handle. Also, cannot use a local coy as I run windows 11 and some libraries I use are obly available on Linux.

This is my Dockerfile:

FROM continuumio/anaconda3

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY ./app /usr/src/app

RUN apt-get update -y
RUN apt-get upgrade -y && apt install gcc -y
RUN apt-get install ffmpeg libsm6 libxext6  -y
RUN curl -O https://raw.githubusercontent.com/airctic/icevision/master/environment.yml 
RUN conda env create -f environment.yml -n myenv
SHELL ["conda", "run", "-n", "myenv", "/bin/bash", "-c"]
RUN pip install uvicorn fastapi pyproj pydantic python-multipart
RUN pip install sahi==0.10.8

EXPOSE 8000

CMD ["conda", "run", "-n", "myenv", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--log-level", "trace"]

The reason to use conda run -n myenv is due to not being able to use conda activate succesfully in daemon mode. I just want to get logs to be able to debug the internal server error I am getting.


Solution

  • I realize this is old, but the issue can be solved with conda option --no-capture-output.

    In other words, change

    CMD ["conda", "run", "-n", "myenv", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--log-level", "trace"]
    

    To

    CMD ["conda", "run", "-n", "myenv", "--no-capture-output", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--log-level", "trace"]