8

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"]
Kitwradr
  • 1,986
  • 3
  • 18
  • 32
  • Hello Ktwradr, which image you have used please let me know, how to reproduce your scenario? I assume that the log file is not set properly to get the stdout of your server logs – PavanDevarakonda Jan 23 '20 at 09:22
  • I have python 3.6 as the base image – Kitwradr Jan 23 '20 at 09:36
  • 2
    Does [setting `ENV PYTHONUNBUFFERED 1`](https://stackoverflow.com/questions/107705/disable-output-buffering/107717#107717) help? (If you wait long enough does it produce a chunk of output?) – David Maze Jan 23 '20 at 10:24

1 Answers1

3

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
sandeep P
  • 63
  • 8
  • i'm using windows any idea where it'll be stored in windows – Kitwradr Jan 23 '20 at 10:47
  • @Kitwradr Sorry i have no idea in windows but you do the second step i have mentioned that will work. – sandeep P Jan 23 '20 at 11:38
  • 2
    @Kitwradr `docker inspect [container-id] | findstr "LogPath"` should provide you the log path. – Nitish Jan 23 '20 at 15:39
  • The path I got was ```/var/lib/docker/containers/f7e2cd41c0706b7a26d9ff5821aa1d792c685826d1c9707422a2a5dfa2e33796/f7e2cd41c0706b7a26d9ff5821aa1d792c685826d1c9707422a2a5dfa2e33796-json.log``` , but var/lib ? Where is this in windows ? @Nitish – Kitwradr Jan 24 '20 at 04:27
  • 2
    @kitwradr have a look at [this](https://stackoverflow.com/questions/41219225/docker-log-driver-json-file-location-for-docker-for-windows) post – Nitish Jan 24 '20 at 06:03