docker: command not found ( mac mini ) only happens in jenkins shell step but work from command prompt

13,140

Solution 1

The PATH which Jenkins jobs start with isn't the same as the path which the Jenkins user sees in bash. In the Jenkins UI you can edit the environment varables (from Manage Jenkins/Configure System), and add the Docker folder to PATH:

PATH -> $PATH:/Users/buildserver/Library/Group\ Containers/group.com.docker/bin/

Some more detail in the answer to this question.

Solution 2

For others (Late but worthy), I installed Jenkins via Brew, so I add Docker's path to the file below: /usr/local/Cellar/jenkins-lts/2.176.3/homebrew.mxcl.jenkins-lts.plist (Whole file looks like below)

<?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>homebrew.mxcl.jenkins-lts</string>
    <key>ProgramArguments</key>
    <array>
      <string>/usr/libexec/java_home</string>
      <string>-v</string>
      <string>1.8</string>
      <string>--exec</string>
      <string>java</string>
      <string>-Dmail.smtp.starttls.enable=true</string>
      <string>-jar</string>
      <string>/usr/local/opt/jenkins-lts/libexec/jenkins.war</string>
      <string>--httpListenAddress=127.0.0.1</string>
      <string>--httpPort=8080</string>
    </array>
    <key>RunAtLoad</key>
    <true />
    <key>EnvironmentVariables</key>
    <dict>
      <key>PATH</key>
      <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Docker.app/Contents/Resources/bin/:/Users/Kh0a/Library/Group\ Containers/group.com.docker/Applications/Docker.app/Contents/Resources/bin</string>
    </dict>
  </dict>
</plist>

Then restart Jenkins' service:

brew services restart jenkins-lts

More question

Solution 3

I have solved the above issue by updating the file

/usr/local/Cellar/jenkins-lts/2.176.3/homebrew.mxcl.jenkins-lts.plist. 

I have added the path of docker in the above file.

<key>EnvironmentVariables</key>
  <dict>
    <key>PATH</key>
<string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Docker.app/Contents/Resources/bin/:/Users/admin/Library/Group\ Containers/group.com.docker</string>
  </dict>
Share:
13,140
vikramvi
Author by

vikramvi

Updated on June 13, 2022

Comments

  • vikramvi
    vikramvi almost 2 years

    I'm facing this weird problem , struggling to solve since almost couple of days.

    Working: On mac mini command prompt , I switch to jenkins user and can run docker command without any problem.

    Not Working: but when I run a jenkins job , inside shell command step docker is not recognized.

    I'm getting error

    docker: command not found
    
    docker --version
    

    But mentioning explicit path of docker , does work

    /Users/buildserver/Library/Group\ Containers/group.com.docker/bin/docker --version
    

    Question : Why docker command can't look into correct path ?

    Permissions

    lrwxr-xr-x 1 buildserver staff 71 Oct 14 10:44 docker -> /Users/buildserver/Library/Group Containers/group.com.docker/bin/docker

    jenkins uses is part of staff group.

    Thanks in advance.

    Regards, Vikram

    • Misko
      Misko over 7 years
      Try echoing and verifying $PATH within the Jenkins job. It's most probably different than on your shell prompt.
  • vikramvi
    vikramvi over 7 years
    + echo '/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/‌​Home/bin:/usr/bin:/b‌​in:/usr/sbin:/sbin:/‌​usr/bin/local:/Users‌​/buildserver/Library‌​/Group\' Containers/group.com.docker/bin/ /Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/H‌​ome/bin:/usr/bin:/bi‌​n:/usr/sbin:/sbin:/u‌​sr/bin/local:/Users/‌​buildserver/Library/‌​Group\ Containers/group.com.docker/bin/ + whoami jenkins + docker --version /Users/Shared/Jenkins/tmp/hudson4594253879036703398.sh: line 4: docker: command not found
  • vikramvi
    vikramvi over 7 years
    I got it fixed with PATH=$PATH:/Applications/Docker.app/Contents/Resources/bin/ which docker /usr/local/bin/docker /Users/buildserver/Library/Group Containers/group.com.docker/bin/docker /Applications/Docker.app/Contents/Resources/bin
  • Robert Ranjan
    Robert Ranjan over 2 years
    you may need to update /Users/admin/Library/Group\ Containers/group.com.docker => /Users/${USER}/Library/Group\ Containers/group.com.docker. ${USER} var may not get expanded in the plist. May need manual update there.