Search code examples
dockerflask

Docker logs command doesn't show any logs


I have a flask app in python which is built into an image , when I try to run it using the command

docker logs -f f7e2cd41c0706b7a26d9ff5821aa1d792c685826d1c9707422a2a5dfa2e33796

It is not showing any logs , it should at least show that flask app has started right ? Note that I am able to hit the flask API from the host and it is working.There are many print statements in the code for this API to have worked , so those print statements should have come in the logs. Am I missing something here ?

Dockerfile is :

FROM python:3.6.8

WORKDIR /app
COPY . /app

#RUN apt-get update -y
#RUN apt-get install python-pip -y

RUN pip install -r requirements.txt

EXPOSE 5001

WORKDIR Flask/
RUN chmod -x main.py ;

CMD ["python", "main.py"]

Solution

  • you can get logs from your host machine. The default logging driver is a JSON-structured file located on local disk

    /var/lib/docker/containers/[container-id]/[container-id]-json. log.
    

    Or the same way as you did will also work.

     sudo docker ps -a
     sudo docker logs -f container-id