Example Dockerfile should document to run python unbuffered
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 50/100
- Loại issue
- Tài liệu
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- dockerfile, python
- Lĩnh vực
- documentation
Hướng nghiên cứu
Bắt đầu với ví dụ trong content.md tại “Create a Dockerfile in your python App Project”, sau đó xem lại Docker Python Guide tại docs.docker.com/language/python/build-images/. Cập nhật cả hai vị trí trong tài liệu để giải thích đầu ra Python không đệm cho nhật ký container, bao gồm ví dụ đã chọn và đảm bảo hướng dẫn phù hợp với hành vi Python được trích dẫn.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
The example Dockerfile in the Create a Dockerfile in your python App Project section in the image documentation should have
ENV PYTHONUNBUFFERED=1
or add the -u option to
CMD [ "python", "-u", "./your-daemon-or-script.py" ]
From https://docs.python.org/3/library/sys.html#sys.stdout:
When interactive, the
stdoutstream is line-buffered. Otherwise, it is block-buffered like regular text files. Thestderrstream is line-buffered in both cases. You can make both streams unbuffered by passing the-ucommand-line option or setting thePYTHONUNBUFFEREDenvironment variable.
Changed in version 3.9: Non-interactive stderr is now line-buffered instead of fully buffered.
When running a container non-interactively, no output from the python script or daemon are flushed to stdout until the block buffer is full (generally DEFAULT_BUFFER_SIZE = 8192) or the container terminates. For daemons which do not terminate and which may not have much logging over its lifetime, nothing may be logged at all.
This makes viewing / tailing the container logs in realtime which by default captures stdout problematic, especially when viewing the logs in conjunction with other services.
Example docker-compose.yaml which demonstrates this issue.
---
services:
demo:
image: python:3
command:
- python
- -c
- |
import time
for i in range(10):
print(i)
time.sleep(1)
No output is written until the container terminates.
It took me a while to figure out what the problem was, believing it was a problem with Docker not flushing logs to the driver (with --log-opt mode=non-blocking) or getting blocked (with --log-opt mode=blocking - the default), until I realised it was a problem specific to Python. Adding changes to the Python image documentation would help users with similar problems. E.g. https://github.com/moby/moby/issues/12447#issuecomment-94416623 and https://stackoverflow.com/questions/29663459/python-app-does-not-print-anything-when-running-detached-in-docker
The Docker Python Guide docs, https://docs.docker.com/language/python/build-images/ should also be updated.
- Ngôn ngữ chính
- Dockerfile
- Star
- 2.8k
- Fork
- 1.1k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của docker-library/python
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
docker-library/python#1151 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
docker-library/python#1150 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 54/100
docker-library/python#1147 ·
-
Provide 3.13t & 3.14t imagesĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
docker-library/python#1082 · 10 bình luận · 40 reaction ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
docker-library/python#1076 · 5 bình luận · 1 reaction ·
Tất cả issue của docker-library/python
Issue tương tự
-
good first issue
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[ordering-review] workshop order graph: 1 confirmed ordering issue, cycles are false positivesĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
githubnext/gh-aw-workshop#6247 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
brucemiller/LaTeXML#2894 ·
-
CONTRIBUTING.md and the release checklist still describe tag-based versioning and a `develop` branchĐang mởdocs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
developmentseed/titiler-cmr#355 ·
Maintainer thường phản hồi trong vòng 1 ngày