-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Start container with timeout? #933
Comments
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 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 Will check that tomorrow and get back to you, Thank you very much!
|
Yeah, |
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, Glad I could help - feel free to reach out if you're still having trouble. |
This pattern is not working in the current version. |
The pattern works, the code needs to be adapted: import docker
from requests.exceptions import ReadTimeout
. . .
# Create container
container = docker_client.containers.create(
image_name,
command,
)
# Run container
container.start()
try:
# Wait for container to finish
container.wait(timeout=30)
except ConnectionError as e:
# If timeout, kill container
container.kill() |
Hi everyone,
Is there any way to start a container with a time limit?
The text was updated successfully, but these errors were encountered: