Skip to content

Instantly share code, notes, and snippets.

@jianingy
Created November 24, 2016 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianingy/8758646477baf96ae8654cd088599b7f to your computer and use it in GitHub Desktop.
Save jianingy/8758646477baf96ae8654cd088599b7f to your computer and use it in GitHub Desktop.
docker-py-test.py
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