简体   繁体   中英

Unstable stdout with docker python

I have next Dockerfile:

FROM ubuntu:16.04
ENV PYTHONIOENCODING=UTF-8
ENV PYTHONUNBUFFERED=1
ADD . /src
WORKDIR /src
ENTRYPOINT ["python3"]
CMD ["-u", "bot.py"]

This dockerfile is used with docker-compose:

version: '3'
services:
  something:
    build: .
    networks:
      - proxy
    volumes:
  - E:\tmp:/src/tmp
ports:
  - "6881-6889:6881-6889/udp"
  - "6881-6889:6881-6889/tcp"
  - "6891:6891/udp"
  - "6891:6891/tcp"
  - "6771:6771/udp"
  - "6771:6771/tcp"
  - "4433-4434:4433-4434/udp"
  - "4433-4434:4433-4434/tcp"
  tor:
    image: "dperson/torproxy"
    networks:
      - proxy
networks:
  proxy:
    driver: bridge

I'm running it with docker "Version 2.0.0.0-win81 (29211) Channel: stable Build: 4271b9e" on Windows 10: "docker-compose up -d"

There is a lot of logging to stdout in this python script. At this moment I'm printing everything with code like this: "print("Exception: " + str(exp), flush=True)"

And I'm almost every time can't get anything that was printed with "docker logs ". Sometimes I have parts of output (in right order). Mostly I have nothing. Why?

python 3.5.2

PS Sorry, flushing everything and everywhere is just my attempts, not a rule.

I found root cause of the problem. I had 2 instances of same script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM