Python script to run docker containers -


i want write python script run docker containers , show logs particular container, have use functions working , starting or stoping containers me. can me show logs containers ?? tried use container.logs() function, not working me, trying study docker-py library ! don't know python, highly appreciated !

#!/usr/bin/python import docker c = docker.client(base_url='unix://var/run/docker.sock',version='1.12',timeout=10) ctr = c.create_container('ubuntu:16.04')  c.start(ctr) 

you using old docker client. run below fix that

pip uninstall docker-py pip install docker 

once done can use below

import docker  c = docker.dockerclient(base_url='unix://var/run/docker.sock',timeout=10) ctr = c.containers.run('ubuntu:16.04',command="bash -c ' for((i=1;i<=10;i+=2)); echo welcome $i times; sleep 10; done'", detach=true)  logs = ctr.logs(stream=true)  line in logs:     print(line) 

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -