【发布时间】:2021-12-30 08:48:36
【问题描述】:
我正在关注aiodocker example,将echo "hello world" 替换为python -c 'print("hello world")',但未显示日志。
以下解决方案(使用PYTHONUNBUFFERED=1、flush=True、-u 标志)无济于事:
Python app does not print anything when running detached in docker
Why doesn't my docker actually log anything?
import asyncio
import aiodocker
async def run_container():
docker = aiodocker.Docker()
container = await docker.containers.create_or_replace(
config={
'Cmd': ['python', '-c', 'print("hello world")'],
'Image': 'python:3.8.2-buster',
},
name="testing"
)
await container.start()
logs = await container.log(stdout=True, stderr=True)
print(''.join(logs))
await container.delete(force=True)
await docker.close()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(run_container())
loop.close()
还有什么问题?
【问题讨论】:
-
'Cmd': ['python', '-c', 'print("hello world")']是否:'Cmd': ['python', '-u', 'print("hello world")']有什么不同? -
@user56700
-u标志也无济于事
标签: python docker logging python-asyncio