Python 2.7.10,Docker 版本 18.03.1-ce-mac65 (24312)
这可能是我对 docker exec_run 命令的工作方式缺乏了解,但我正在努力让它工作。以下代码可以正常工作
from __future__ import print_function
import docker
if __name__ == '__main__':
client = docker.from_env()
image = client.images.pull('oraclelinux:7')
container = client.containers.run('oraclelinux:7',
command='ls',
stderr=True,
stdout=True,
auto_remove=False,
remove=False,
detach=True
)
log = container.logs(stdout=True, stderr=True, stream=True)
for line in log:
print(line, end='')
container.stop()
print(container.status)
container.remove()
Run Code Online (Sandbox Code Playgroud)
并返回根目录中的目录列表。但是,我希望以下内容是等效的失败。
from __future__ import print_function
import docker
if __name__ == '__main__':
client = docker.from_env()
image = client.images.pull('oraclelinux:7')
container = client.containers.create('oraclelinux:7',
command='/bin/bash',
auto_remove=False)
container.start()
log = container.exec_run('ls',
stderr=True,
stdout=True,
detach=True)
for line …Run Code Online (Sandbox Code Playgroud)