question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using docker.client.DockerClient.containers.run with auto_remove=True causes a crash

See original GitHub issue

What happens is straightforward: setting auto_remove=True in the arguments to run() causes the container to be removed before the Python client attempts to read the logs. This then raises an error like:

docker.errors.NotFound: 404 Client Error: Not Found ("No such container: 0e9a9dd8072a1b80ead74bc47466493ffea92eca7acf1c5f3b29ce6faf861161")

This is not how executing docker run -rm works, where the output still goes to stdout, and it means that calling run() with auto_remove=True isn’t useful.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
StephenPCGcommented, Dec 20, 2017

@feliperuhland @shin- Thank you for pointing that out! I didn’t realize there is a remove param and the difference between auto_remove. That solves my problem.

2reactions
thiagofigueirocommented, Nov 28, 2017

+1 Minimal steps to reproduce using example from manual:

In [1]: import docker
In [2]: client = docker.from_env()
In [3]: client.containers.run('alpine:2.7', 'echo hello world')
Out[3]: b'hello world\n'
In [4]: client.containers.run('alpine:2.7', 'echo hello world', auto_remove=True)
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
(...)
~/.pyenv/versions/3.6.3/lib/python3.6/site-packages/docker/errors.py in create_api_error_from_http_exception(e)
     29         else:
     30             cls = NotFound
---> 31     raise cls(e, response=response, explanation=explanation)
     32
     33

NotFound: 404 Client Error: Not Found ("No such container: 6151f0219d2dbb90df7288f30f1221e817fd9d3c63afdbadf2ad2a87ba6e7e45")
Read more comments on GitHub >

github_iconTop Results From Across the Web

Containers — Docker SDK for Python 6.0.1 documentation
command (str or list) – The command to run in the container. auto_remove (bool) – enable auto-removal of the container on daemon side...
Read more >
Examples using the Docker Engine SDKs and Docker API
This first example shows how to run a container using the Docker API. On the command line, you would use the docker run...
Read more >
What's the difference between auto_remove and remove in ...
I'm see that there are two boolean flags in client.containers.run : auto_remove (bool) – enable auto-removal of the container on daemon side ...
Read more >
docker-sdk-python Documentation - Read the Docs
A Python library for the Docker Engine API. It lets you do anything the docker command does, but from within. Python apps –...
Read more >
Docker client - Python on whales - GitHub Pages
from python_on_whales import docker print(docker.run("hello-world")) ... Let's say you want to use estargz to run a container immediately, without waiting ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found