Example Dockerfile should document to run python unbuffered
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 50/100
- Tipo de issue
- Documentação
- Clareza
- Claramente especificada
- Status de atividade
- Estagnada
- Stack de tecnologia
- dockerfile, python
- Domínio
- documentation
Direção de pesquisa
Comece com o exemplo em content.md em “Create a Dockerfile in your python App Project” e, em seguida, revise o Docker Python Guide em docs.docker.com/language/python/build-images/. Atualize os dois locais da documentação para explicar a saída Python sem buffer para os logs dos contêineres, incluir o exemplo escolhido e garantir que as orientações correspondam ao comportamento do Python citado.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- Dockerfile
- Estrelas
- 2.8k
- Forks
- 1.1k
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Preparar o ambiente
Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de docker-library/python
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
docker-library/python#1151 ·
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 38/100
docker-library/python#1150 · 1 comentário ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 54/100
docker-library/python#1147 ·
-
Provide 3.13t & 3.14t imagesAberta
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 45/100
docker-library/python#1082 · 10 comentários · 40 reações ·
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 55/100
docker-library/python#1076 · 5 comentários · 1 reação ·
Todas as issues de docker-library/python
Issues semelhantes
-
good first issue
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 75/100
Mantenedores costumam responder em até 1 dia
-
[ordering-review] workshop order graph: 1 confirmed ordering issue, cycles are false positivesAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
githubnext/gh-aw-workshop#6247 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
brucemiller/LaTeXML#2894 ·
-
CONTRIBUTING.md and the release checklist still describe tag-based versioning and a `develop` branchAbertadocs
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
developmentseed/titiler-cmr#355 ·
Mantenedores costumam responder em até 1 dia