Hi everyone,
Is there any way to start a container with a time limit?
Is this what you're looking for?
import docker
from requests.exceptions import ReadTimeout
c = docker.Client()
ctnr = c.create_container('busybox', 'sleep 45')
c.start(ctnr)
try:
c.wait(ctnr, timeout=5)
except ReadTimeout as e:
print('too slow!')
c.kill(ctnr)
Not exactly.
In fact, I am executing untrusted code inside a container and I want to
limit that code execution time.
Isn't my script stopping at c.start() and wait for container's result?
Or am I completely lost and my script hangs on c.stop() while the code is
executed inside the container? If yes, then your solution might just work!
Will check that tomorrow and get back to you,
Thank you very much!
Le 9 févr. 2016 15:04, "Joffrey F" [email protected] a écrit :
Is this what you're looking for?
import dockerfrom requests.exceptions import ReadTimeout
c = docker.Client()
ctnr = c.create_container('busybox', 'sleep 45')
c.start(ctnr)try:
c.wait(ctnr, timeout=5)except ReadTimeout as e:
print('too slow!')
c.kill(ctnr)—
Reply to this email directly or view it on GitHub
https://github.com/docker/docker-py/issues/933#issuecomment-182037419.
Yeah, Client.start is non-blocking. Client.stop will typically block until the container is stopped, or the command has timed out (default 10 seconds).
Mind = blown. Don't know how I could have missed that. Probably the 'docker run command' that had me suppose Client.start was doing the same thing.
Yeah, docker run is a combination of create_container + start + wait (unless you use the -d parameter).
Glad I could help - feel free to reach out if you're still having trouble.
This pattern is not working in the current version.
Most helpful comment
Is this what you're looking for?