Python app does not print anything when running detached in docker

前端 未结 11 1514
不思量自难忘°
不思量自难忘° 2020-11-29 16:54

I have a Python (2.7) app which is started in my dockerfile:

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

main.py prints some strings when it is s

11条回答
  •  青春惊慌失措
    2020-11-29 17:21

    You can see logs on detached image if you change print to logging.

    main.py:

    import time
    import logging
    print "App started"
    logging.warning("Log app started")
    while True:
        time.sleep(1)
    

    Dockerfile:

    FROM python:2.7-stretch
    ADD . /app
    WORKDIR /app
    CMD ["python","main.py"]
    

提交回复
热议问题