简体   繁体   English

无法从 docker-compose 容器打印到 Docker 桌面应用程序

[英]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.但由于某种原因它不起作用。

What I already tried using:我已经尝试使用的是:

  • -u flag -u标志
  • stdin_open: true and tty: true in the docker-compose stdin_open: truetty: true docker docker-compose中的 true
  • flush=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:环境:

  • PYTHONUNBUFFERED=1 PythonUNBUFFERED=1

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.

相关问题 Docker-compose Flask 应用程序不打印“打印”的输出 - Docker-compose flask app not printing output from 'print' 无法从 docker-compose 的另一个容器访问 api 的 docker 容器 - docker container of api not accessible from another container of docker-compose TesseractNotFoundError:两个docker容器python应用程序(docker-compose) - TesseractNotFoundError: two docker container python app (docker-compose) Docker 无法打开文件以在使用 django 的容器中运行 python 应用程序,使用 ZBAEDB53E845AE71F13945FCC00572 - Docker can't open file to run the python application in a container with django using docker-compose 无法连接到 mysql docker-compose - can't connect to mysql docker-compose docker-compose exec导致[Errno 2]没有此类文件或目录:docker容器中的'docker-compose':'docker-compose' - docker-compose exec causes [Errno 2] No such file or directory: 'docker-compose': 'docker-compose' in docker container 使用docker-compose up与docker-compose run从容器内部执行容器中的命令 - executing commands in containers from within a container using docker-compose up vs docker-compose run Dockerfile 无法复制 & Docker-compose 卷不与容器同步 - Dockerfile can't copy & Docker-compose volume does not sync with container 为什么“ docker-compose run”可以在容器外部创建文件? - Why can “docker-compose run” create files outside the container? 从 docker-compose 运行时容器以代码 0 退出 - Container exited with code 0 when run from docker-compose
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM