通过python操作Docker
pip install docker
import docker
client = docker.from_env()
from docker import DockerClient
client2 = DockerClient(base_url='unix://var/run/docker.sock')
命令:client.containers.run()
Returns:
The container logs, either STDOUT, STDERR, or both, depending on the value of the stdout and stderr arguments.
STDOUT and STDERR may be read only if either json-file or journald logging driver used. Thus, if you are using none of these drivers, a None object is returned instead. See the Engine API documentation for full details.
If detach is True, a Container object is returned instead.
Raises:
client.containers.run('<image>', '<command>')
example:
client.containers.run('alpine, 'echo hello world')
container = client.containers.run('<image>', detach=True)
container.logs()
container.logs()
logs = container.logs(stream=True)
for line in logs:
print(output)
exit_code = container.wait()
print(exit_code)
output:
{'Error': None, 'StatusCode': 0}