0

I am using Python 3.8.5, on Mac. Need to find location of the docker executable. The following code

DOCKER_PATH = shutil.which('docker')

return empty result on my Mac when I run it from Eclipse. If I open terminal, I do have docker installed

which docker
/usr/local/bin/docker

Also this work fine

python
Python 3.8.5 (default, Oct 22 2020, 19:13:38) 
[Clang 11.0.3 (clang-1103.0.32.59)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import shutil
>>> shutil.which('docker')
'/usr/local/bin/docker'
>>> 

Any ideas, what is wrong?

Thanks

cactus
  • 117
  • 6
  • Eclipse may not have `/usr/local/bin` defined in its `PATH` environment variable. – metatoaster Aug 18 '21 at 07:24
  • Eclipse doesn't use the same PATH as other applications? Is there way Eclipse will use the same PATH? – cactus Aug 18 '21 at 07:26
  • You may wish to verify by running Python code that will `import os` and then `print(os.environ['PATH'])`, along with `os.path.isfile('/usr/local/bin/docker')`. I don't have access to your machines to do this for you. – metatoaster Aug 18 '21 at 07:28
  • hm...indeed print(os.environ['PATH']) returns /usr/bin:/bin:/usr/sbin:/sbin and os.path.isfile('/usr/local/bin/docker') return True. But then i am not sure where is the fault, either PATH is not passed to Eclipse or the way i use shutil.which('docker') is not the correct way to find location of docker executable – cactus Aug 18 '21 at 07:36
  • It's likely due to Eclipse started with a specific restricted set of environment variables defined - check the related startup scripts for Eclipse on your system, or see how Eclipse handles environment variables. – metatoaster Aug 18 '21 at 07:38
  • Related [thread](https://stackoverflow.com/questions/7048216/environment-variables-in-eclipse) and [thread](https://stackoverflow.com/questions/55678675/append-to-path-environment-variable-in-eclipse) – metatoaster Aug 18 '21 at 07:40
  • You shouldn't need a `docker` binary in this context; can you use the [Docker SDK for Python](https://docker-py.readthedocs.io/en/stable/) instead? Also remember that you can pretty easily use Docker to take over the whole host; be extra careful with basic security concerns, and consider hard whether you _need_ Docker access, or whether you can use other techniques instead. – David Maze Aug 18 '21 at 10:14

0 Answers0