[英]Can't print from docker-compose container to the Docker desktop app
I am trying to print from a docker-compose
container to the terminal/docker desktop app or wehere ever I will be able to see it.我正在尝试从 docker docker-compose
容器打印到终端/docker 桌面应用程序,否则我将能够看到它。 But it doesn't work for some reason.但由于某种原因它不起作用。
-u
flag -u
标志stdin_open: true
and tty: true
in the docker-compose
stdin_open: true
和tty: true
docker docker-compose
中的 trueflush=True
in the print statment打印语句中的flush=True
But none of it working.但都没有用。
Can someone please help me figer this out?.有人可以帮我解决这个问题吗?
I am running it using the following command:我正在使用以下命令运行它:
docker-compose up -d
this is my docker-compose:这是我的 docker-compose:
version: '3.5'
environment:
PYTHONUNBUFFERED=1
services:
relay:
container_name: relay
image: image
command: python3 -u server.py
expose:
- "443"
networks:
pNetwork1:
ipv4_address: 10.1.0.3
stdin_open: true
tty: true
and this is my server.py:这是我的 server.py:
def main():
print("Please Work!", flush=True)
if __name__ == "__main__":
main()
You can try setting the environment variable PYTHONUNBUFFERED in the docker-compose.yml file.您可以尝试在 docker-compose.yml 文件中设置环境变量 PYTHONUNBUFFERED。
environment:环境:
This will force python to not buffer the output and should print the output to the terminal.这将强制 python 不缓冲输出并且应该将输出打印到终端。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.