Created
November 24, 2016 06:37
-
-
Save jianingy/8758646477baf96ae8654cd088599b7f to your computer and use it in GitHub Desktop.
docker-py-test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import absolute_import, unicode_literals | |
from docker import Client as DockerClient | |
from time import sleep | |
def run_and_output(cli, c, cmd): | |
exe = cli.exec_create(c['Id'], cmd=cmd, tty=True) | |
stream = cli.exec_start(exec_id=exe['Id'], stream=True) | |
i = 0 | |
for line in stream: | |
i += 1 | |
print i, line | |
def main(): | |
cli = DockerClient(base_url="http://u1:2375") | |
name = 'test-container' | |
c = cli.create_container(image='traci', command='/bin/sleep 30') | |
cli.start(c) | |
run_and_output(cli, c, "df") | |
run_and_output(cli, c, "sleep 5") | |
run_and_output(cli, c, "free -m") | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment