3

So I am attempting to run an ant build in an eclipse environment on MacOS Sierra (V 10.12.5) that will build a docker image, get the image parts and push the image to an artifactory repo.

When I go to run the build image target, the build fails with this error:

java.io.IOException: Cannot run program "docker" (in directory my/working/directory) error=2, No such file or directory

After browsing online for the past hour or so it seems like it might be a version issue but I have the latest version of docker and eclipse as well as Java SE 8 [1.8.0_144].

I have gone to the directory that supposedly doesn't exist (it does) and tried running some docker commands and they all work fine, the daemon is running and there appear to be no issues on the end.

This isn't all of the code from my ant build but this is the start of the section that it fails on:

    <exec executable="docker" dir="docker" failonerror="true">
        <arg value="build" />
        <arg line="--build-arg label=${label}" />

Any advice on what to do, what the issue is would be much appreciated.

PrimeOfKnights
  • 426
  • 5
  • 17
Robbie Avill
  • 55
  • 1
  • 7

2 Answers2

0

Create an environment.plist file in ~/Library/LaunchAgents/ with this content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>my.startup</string>
  <key>ProgramArguments</key>
  <array>
    <string>sh</string>
    <string>-c</string>
    <string>launchctl setenv PATH $PATH:/usr/local/bin</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
</dict>
</plist>

Then to activate the file use commands:

launchctl load ~/Library/LaunchAgents/environment.plist launchctl start ~/Library/LaunchAgents/environment.plist

Thomas.L
  • 321
  • 1
  • 6
  • There is no .MacOSX directory – Robbie Avill Aug 22 '17 at 13:45
  • are you sure? it should be a hidden directory – Thomas.L Aug 22 '17 at 13:47
  • if it doesn't exist you can create it `mkdir ~/.MacOSX` then you create `environment.plist` with the path value – Thomas.L Aug 22 '17 at 13:49
  • 100% sure it doesn't exist now, unless it would still be hidden after ls -la. so I can just copy and paste that docker directory into that file, doesn't need anything else? – Robbie Avill Aug 22 '17 at 13:51
  • yeah it should be enough, create the file and run this command `defaults write $HOME/.MacOSX/environment PATH "/docker/path:$PATH"` – Thomas.L Aug 22 '17 at 13:57
  • I can't find the full path to docker, I tried the "which docker" command which returned /usr/local/bin/docker but /docker isn't a folder so I don't think this is the correct directory to use for the path, any chance you know how to find the path to dockers bin? – Robbie Avill Aug 23 '17 at 09:22
  • `docker` is the binary itself, the directory is `/usr/local/bin` so you need to do: `defaults write $HOME/.MacOSX/environment PATH "/usr/local/bin:$PATH"` – Thomas.L Aug 23 '17 at 09:25
  • I have done that now and unfortunately still having the same error after restarting the eclipse environment as well as the Mac. – Robbie Avill Aug 23 '17 at 10:17
  • looks like `/.MacOSX/environment.plist` is not supported since 10.4, I updated my answer with different way to achieve it, please check now – Thomas.L Aug 23 '17 at 10:38
  • Created the file, ran those commands,restarted the Mac but unfortunately still having the same issue with my build – Robbie Avill Aug 23 '17 at 12:19
  • Can you run this in Eclipse `System.out.println(System.getenv("PATH"))` Also run in terminal `echo $PATH` and give the output please. otherwise you can call `docker` command with absolute path in Java : `/usr/local/bin/docker` but would be good to find the issue – Thomas.L Aug 23 '17 at 12:22
  • Also please make sure you start Eclipse with: `/Applications/eclipse/eclipse` ....NOT `/Applications/eclipse/Eclipse.app` – Thomas.L Aug 23 '17 at 12:27
  • I have been opening the .app for all of this, could that be the issue? Not sure how to open it up not from the .app – Robbie Avill Aug 23 '17 at 12:46
  • start it using `/Applications/eclipse/eclipse` – Thomas.L Aug 23 '17 at 12:56
  • The path from the terminal is - "/usr/local/bin:/usr/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin" From Eclipse it is: "/usr/bin:/bin:/usr/sbin:/sbin – Robbie Avill Aug 23 '17 at 12:59
  • there is no eclipse .app within the applications folder, they're all in their own separate eclipse folder (multiple versions in one folder) and only the .app is in there for each of them - Would it be worth doing a fresh install of eclipse? – Robbie Avill Aug 23 '17 at 13:01
  • can you try that way please : `sudo touch /etc/launchd.conf` and in file add : `setenv PATH /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin` and then reboot, and start application as you normally do (double-clicking the eclipse icon) – Thomas.L Aug 23 '17 at 13:29
  • if it works please revert the previous solution as they are duplicating entries in your PATH. the problem is that launching application from terminal or as GUI application, the parent process is different. When using GUI the parent process is `launchd` but using terminal , it will be a child process of terminal so the environment is different – Thomas.L Aug 23 '17 at 13:32
  • I added that line to that file, rebooted and ran eclipse from the .app as normal but unfortunately no change, it is still failing with the same error – Robbie Avill Aug 23 '17 at 13:55
  • ok can you do `launchctl < /etc/launchd.conf; sudo launchctl < /etc/launchd.conf` and reboot again ? sorry for that :) – Thomas.L Aug 23 '17 at 13:57
  • in worst case what you can do is start Eclipse from Terminal as your environment in Terminal is correctly setup: `open /Applications/eclipse/Eclipse.app` – Thomas.L Aug 23 '17 at 14:01
  • Okay so I tried the launchctl stuff but after a reboot that didn't make a difference so I tried running Eclipse from the terminal like you said and that worked!! :D what would be a permanent solution to this? or do I now have to open eclipse from the terminal every time? – Robbie Avill Aug 23 '17 at 14:13
  • Cool! at least :)) as a work-around you can launch it using the Terminal for now..we need to fix your global environment path, which version of OSX are you running exactly ? – Thomas.L Aug 23 '17 at 14:15
  • Thank you so much! I am currently running MacOS Sierra v10.12.5 – Robbie Avill Aug 23 '17 at 14:19
0

As suspected the issue was due to the environment path not being set when opening up the eclipse.app

The solution for this was found here - Launch mac eclipse with environment variables set

Robbie Avill
  • 55
  • 1
  • 7