Python Docker API需要知道要包含的attach(**kwargs)的语法

2024-10-01 04:54:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试运行以下命令:

# container started
container = PythonDockerAPIs.runContainerWithoutLogs(alpineImage, 'tail -f /dev/null', detach=True)
#execute the command
cmd1 = container.exec_run('ls -ltr',stream=True, detach=True)

有没有一种方法可以使用attach(**kwargs)将日志附加到此容器并在以后打印日志?在

https://docker-py.readthedocs.io/en/stable/containers.html


Tags: thedev命令trueexecutecontainernullcommand
1条回答
网友
1楼 · 发布于 2024-10-01 04:54:21

**kwargs只是表示列出的参数是“关键字参数”,因此对于^{} function,它以任何顺序使用keyword=value形式接受这些参数(或“参数”):

  • stdout(bool)–包括stdout。在
  • stderr(bool)–包括stderr。在
  • stream(bool)–以迭代器的形式逐步返回容器输出 而不是一根线。在
  • logs(bool)–包括容器以前的输出。在

要调用此函数,请执行以下操作:

logs = container.attach(stdout=True, stderr=True, stream=True, logs=True)

注意,文档还声明^{}函数是attach函数的包装器,因此可以使用该函数而不是{}。在

编辑:

完整用法示例:

^{pr2}$

相关问题 更多 >