containers.run() hangs without output when image is missing (+/- invalid mount)
See original GitHub issueHi all,
First of all thanks for the continued work on this SDK – it’s been very useful for making quick work of some local e2e tests. I ran into this problem while a colleague was trying to run some tests that “ran on my machine”.
Issue
TL;DR - If you do not have the image you want to run pulled (for example minio/minio
), and you have a configuration error (such as an invalid mount
specified), the containers.run
command will hang (due to one or more silent failures) – the container will never be pulled, the program will not continue past or error, and the underlying mount problem won’t cause an error either – to the end user it just looks like a hang with no output.
The first progress we were able to make was installing the minio/minio
image with the docker
CLI directly – this got rid of the missing image problem (maybe docker-py
doesn’t fetch missing automatically, I thought this was docker run
standard behavior), and exposed an invalid mount
configuration issue. The mount configuration issue has to do with how OSX temp directories are created (once the error was visible it was easy to fix):
E docker.errors.APIError: 502 Server Error: Bad Gateway ("b'Mounts denied: \r\nThe path /var/folders/wj/x6b1l_7s1yg977rxrrjpsc8h0000gn/T/project-9dk0ewdx\r\nis not shared from OS X and is not known to Docker.\r\nYou can configure shared paths from Docker -> Preferences... -> File Sharing.\r\nSee https://docs.docker.com/docker-for-mac/osxfs/#namespaces for more info.\r\n.'")
this issue is due to namespacing on OSX, and the interaction with python’s tempfile
functionality:
import tempfile
# Create tmp local directory for minio to use
d = tempfile.mkdtemp(prefix="e2e-minio") # /var/folders/wj/x6b1l_7s1yg977rxrrjpsc8h0000gn/T/project-minio9dk0ewdx
The fact that this folder can’t be used by the spawned docker container is more of a gotcha more than a bug (maybe both of these issues are), so I’m not sure exactly what should be done (maybe it’s just adding more documentation).
The main issue is the missing container appearing as a hang (which might have been exacerbated by the invalid mount
issue), with no output (error or otherwise) returned to the user.
Reproduction
Steps:
- Install
docker
(native) 18.02 (latest as of 02/16) on OSX - Create a python project that uses
tmpfile.mkdtemp
- Create a client with
docker.from_env()
- Run
docker_client.containers.run
w/ a mounted directory that is the temp directory
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (1 by maintainers)
Top GitHub Comments
Thanks for this, new to Docker and this took way to much time to figure out. Seems a simple update to the docs is in order https://docs.docker.com/engine/api/sdk/examples/
to
Edit: Further to the above, pulling a remote image hangs even with the above. Logging in first works
Thanks to the docs. I pulled entire library of ubuntu image.